Here's my test piece of code. As you can see, I'm just beginning :)



.data
Err db "Nope",0
SqlEnv dd 0
SqlCon dd 0
.code

; Create an environment to work with
mov SqlEnv,0
invoke SQLAllocHandle,SQL_HANDLE_ENV,SQL_NULL_HANDLE,addr SqlEnv
mov ebx,eax
.if !((eax == SQL_SUCCESS) || (eax == SQL_SUCCESS_WITH_INFO))
invoke dw2a,ebx,addr buffer1
invoke MessageBox,hWin,addr Err,addr buffer1,MB_OK
.endif

; Tell ODBC which version we're expecting (this is required here!)
.data
sqldVer dd SQL_OV_ODBC2
.code
invoke SQLSetEnvAttr,SqlEnv,SQL_ATTR_ODBC_VERSION,addr sqldVer,0
mov ebx,eax
.if !((eax == SQL_SUCCESS) || (eax == SQL_SUCCESS_WITH_INFO))
invoke dw2a,ebx,addr buffer1
invoke MessageBox,hWin,addr Err,addr buffer1,MB_OK
.endif

; Create the connection object
invoke SQLAllocHandle,SQL_HANDLE_DBC,SqlEnv,addr SqlCon
mov ebx,eax
.if !((eax == SQL_SUCCESS) || (eax == SQL_SUCCESS_WITH_INFO))
invoke dw2a,ebx,addr buffer1
invoke MessageBox,hWin,addr Err,addr buffer1,MB_OK
.endif

; Connect to the database!
.data
sqlsCon db "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\mydb.mdb;",0
sqlsUID db 0
sqlsPSW db 0
.code
invoke SQLConnect,SqlCon,addr sqlsCon,sizeof sqlsCon-1,addr sqlsUID,sizeof sqlsUID-1,addr sqlsPSW,sizeof sqlsPSW-1
mov ebx,eax
.if !((eax == SQL_SUCCESS) || (eax == SQL_SUCCESS_WITH_INFO))
invoke dw2a,ebx,addr buffer1
invoke MessageBox,hWin,addr Err,addr buffer1,MB_OK
.endif

; Disconnect
invoke SQLDisconnect,SqlCon
; Free connection handle and environment handle
invoke SQLFreeHandle,SQL_HANDLE_DBC,SqlCon
invoke SQLFreeHandle,SQL_HANDLE_ENV,SqlEnv



Just plug this code into the Masm32 installation test template, for the about box or something. Also don't forget to include(lib) odbc.inc / .lib.
I get 4 messageboxes with the numbers 2199977984, 2200043519, again 2200043519, and 65534. None of these numbers appears to be a valid return value for any of these functions (except the last one, which could be SQL_ERROR if the return value was a WORD, which it isn't :( )

I've been staring at this for several hours now, and I'm really frustrated as to why I can't get this extremely basic code to work.
Please, anybody?:confused:
Posted on 2002-02-02 09:18:21 by Qweerdy
Queerdy,

in my odbc progs i do:

invoke SQLxxxxx
movsx eax,ax
.if (eax == SQL_xxx ...)

So possibly you should also test the low word of eax only.

japheth
Posted on 2002-02-02 10:03:23 by japheth
it's ax indeed :)

also

.data
sqldVer dd SQL_OV_ODBC2
.code
invoke SQLSetEnvAttr,SqlEnv,SQL_ATTR_ODBC_VERSION,addr sqldVer,0



SQLSetEnvAttr expects a value, not a pointer so just use SQL_OV_ODBC2

I attached a working version of your code so you can compare. The only thing that's different is that I made a DSN entry named 'test' which I use instead of your connectionstring. There's something not OK with the coinnectionstring but it's long since I constructed one by hand and I don't have the correct info here. Sorry.

-H-
Posted on 2002-02-02 11:58:59 by Hiroshimator
Coooool... thanks :cool: :alright:

Now if I just figure out the conn string. It works in ASP, but of course that works with ADO.... Oh well, I'll do some work myself now :rolleyes:

Edit after having opened the zip :) :
And thanks for the attached tutes, wonder why I didn't find em? This really helped:

One disadvantage of SQLConnect is that, you have to create a DSN before you can connect to the data source. SQLDriverConnect offers more flexibility.
Posted on 2002-02-02 12:10:26 by Qweerdy
I forgot your code :o

yes, they're Iczelion's tuts :)
they're very good
Posted on 2002-02-02 12:34:19 by Hiroshimator