alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
352 stars 140 forks source link

Failing 4D SQL connections #134

Open WRFS-Ethan opened 5 years ago

WRFS-Ethan commented 5 years ago

package main

import ( "database/sql" "fmt" "log"

_ "github.com/alexbrainman/odbc"

)

func main() { db, err := sql.Open("odbc", "DSN=Power BI;Uid=USERNAME;Pwd=PASSWORD") if err != nil { log.Fatal(err) } defer db.Close() err = db.Ping() if err != nil { fmt.Println("got an error:", err) } }

gives me this error:

Exception 0x406d1388 0x1000 0x180094d88 0x7ff8c8ee9149 PC=0x7ff8c8ee9149

syscall.Syscall9(0x7ff8ad494650, 0x8, 0xfb7460, 0x0, 0xc00008a0a0, 0xfffffffffffffffd, 0x0, 0x0, 0x0, 0x0, ...) C:/Go/src/runtime/syscall_windows.go:198 +0x102 github.com/alexbrainman/odbc/api.SQLDriverConnect(0xfb7460, 0x0, 0xc00008a0a0, 0xfffd, 0x0, 0x430000, 0x0, 0x100000000000000, 0x0) C:/FSP-Mini/src/github.com/alexbrainman/odbc/api/zapi_windows.go:108 +0xfd github.com/alexbrainman/odbc.(Driver).Open(0x5cb5e0, 0x4fa8f0, 0x26, 0x0, 0x0, 0x0, 0x0) C:/FSP-Mini/src/github.com/alexbrainman/odbc/conn.go:34 +0x111 database/sql.dsnConnector.Connect(0x4fa8f0, 0x26, 0x50c220, 0x5cb5e0, 0x50c640, 0xc00005c058, 0x0, 0x0, 0x0, 0x0) C:/Go/src/database/sql/sql.go:637 +0x4c database/sql.(DB).conn(0xc0000a0000, 0x50c640, 0xc00005c058, 0xc000081f01, 0x4a106c, 0x42a53a, 0xc000081ea8) C:/Go/src/database/sql/sql.go:1177 +0x13c database/sql.(DB).PingContext(0xc0000a0000, 0x50c640, 0xc00005c058, 0x18, 0xc000081f20) C:/Go/src/database/sql/sql.go:731 +0x99 database/sql.(DB).Ping(0xc0000a0000, 0x4fc7b8, 0xc0000a0000) C:/Go/src/database/sql/sql.go:749 +0x4a main.main() C:/FSP-Mini/API-M/ODBCTest/main.go:17 +0xdf

goroutine 19 [select]: database/sql.(*DB).connectionOpener(0xc0000a0000, 0x50c600, 0xc000058180) C:/Go/src/database/sql/sql.go:1001 +0xef created by database/sql.OpenDB C:/Go/src/database/sql/sql.go:671 +0x164

goroutine 20 [select]: database/sql.(*DB).connectionResetter(0xc0000a0000, 0x50c600, 0xc000058180) C:/Go/src/database/sql/sql.go:1014 +0x102 created by database/sql.OpenDB C:/Go/src/database/sql/sql.go:672 +0x19a rax 0x0 rbx 0xccae0 rcx 0x0 rdi 0xbeba0 rsi 0x1800c1600 rbp 0x80 rsp 0x7cd910 r8 0x0 r9 0x0 r10 0x9077e r11 0x3 r12 0x180078894 r13 0x1 r14 0x180000000 r15 0x0 rip 0x7ff8c8ee9149 rflags 0x202 cs 0x33 fs 0x53 gs 0x2b exit status 2

I am using 4D v16 sql driver on windows. sql.Open always works fine however any other db function calls cause this panic. Thank you for any and all clarity about this issue!

alexbrainman commented 5 years ago

Exception 0x406d1388 0x1000 0x180094d88 0x7ff8c8ee9149 PC=0x7ff8c8ee9149

syscall.Syscall9(0x7ff8ad494650, 0x8, 0xfb7460, 0x0, 0xc00008a0a0, 0xfffffffffffffffd, 0x0, 0x0, 0x0, 0x0, ...) C:/Go/src/runtime/syscall_windows.go:198 +0x102 github.com/alexbrainman/odbc/api.SQLDriverConnect(0xfb7460, 0x0, 0xc00008a0a0, 0xfffd, 0x0, 0x430000, 0x0, 0x100000000000000, 0x0)

Looking at this stack trace - the exception was raised during SQLDriverConnect ODBC API call (inside your 4D SQL ODBC driver). You need to ask the driver developers why they raised the exception.

The exception number of 0x406d1388 looks very strange. Googling for 0x406d1388 I find this

https://randomascii.wordpress.com/2015/10/26/thread-naming-in-windows-time-for-something-better/

The main flaws occur because thread naming on Windows works by raising an exception. There is a convention that says that debuggers should watch for the exception code 0x406D1388 – yes, that is just an arbitrary magic number with no intrinsic meaning – and look for magic values in the associated exception record. The debugger has to do something like this:

Call WaitForDebugEvent. If there is an exception, and if the exception code is 0x406D1388, and if the number of parameters is the right value, then reinterpret_cast the exception information. Look in that struct and if dwType is equal to 4096, and dwFlags is zero, then use ReadProcessMemory to grab the thread name from the debuggee’s memory.

Oh, where to start…

I would suspect your driver DLL thinks it is running under debugger. Are you running program under debugger?

Alex

WRFS-Ethan commented 5 years ago

Would using the go run command or go build command give you a debug version of the file? I am using Atom as my IDE I can't find anything about a GO debugger. I am trying to get in touch with the driver developers at the moment!

alexbrainman commented 5 years ago

Would using the go run command or go build command give you a debug version of the file? I am using Atom as my IDE I can't find anything about a GO debugger. I am not talking about how you produce executable, I am talking about how you are running executable.

You can use whatever tool you like to produce executable. If you run executable from Windows cmd prompt or from Windows Explorer, then you are not running it under debugger.

Alex

WRFS-Ethan commented 5 years ago

I am not using any sort of debugging mode then, I am pretty confused because the connection works just fine in python and C# when I tried

ghost commented 3 years ago

@WRFS-Ethan did you ever find a solution? I have the exact same behaviour - works fine in debug mode, but not when running normally.