ODBC QConnect

Started by mpiaser, June 22, 2013, 07:22:59 AM

Previous topic - Next topic

mpiaser

I am trying to get ODBC and Winbatch to work together. I'd swear I had this working but now I'm getting an error on the qConnect function (return code -1). The qAllocEnv and qAllocConnect functions work. I have created a DSN and using the test button it works. I don't see a way to get more debugging information as to why the qConnect fails.

I am talking to a SQL Server database which is on another machine. I am using SQL Server Native Client 11 and a system DSN called TEST.

The IF statement that is "causing" the failure is If (retcode != @qSuccess) && (retcode != @qSuccessInfo) - I don't know where @qSuccess or @qSuccessInfo are defined nor what their values are.

AddExtender("wwodb44i.dll")
;INITIALIZE VARIABLES
MyDataSource="TEST"
MyTableName="tbl_external_restore_dates"
;THIS ALLOCATES A SQL ENVIRONMENT HANDLE
henv = qAllocEnv()
If henv == -1
;THIS RETURNS LAST CODE SET BY LAST SQL FUNCTION
retcode = qLastCode()
Message("qAllocEnv failed", retcode)
Exit
Endif


;ALLOCATES A SQL CONNECTION HANDLE - MAXIMUM
;OF 10 OPEN CONNECTION HANDLES
hdbc = qAllocConnect(henv)
If hdbc == -1
retcode = qLastCode()
Message("qAllocConnect failed", retcode)
Exit
Endif



;CONNECTS TO THE "SAMPLE" DATA SOURCE (with the data source name 'ContactDSN')
retcode = qConnect(hdbc, MyDataSource, "", "")
If (retcode != @qSuccess) && (retcode != @qSuccessInfo)
Message("qConnect failed", retcode)
Exit
Endif







stanl

I replied on old board.

mpiaser

I put message boxes so I could see the values
@qSuccess = 0
@qSucessInfo = 1

so the IF statement: If (retcode != @qSuccess) && (retcode != @qSuccessInfo)
executes and displays the error because retcode = -1.  Hence, a retcode = -1 must mean failure of some sort.

stanl

Not sure about those properties, but normally in ODBC/ADO/OLEDB 0=False and non-zero=True (normally 1 or -1).

Deana

I recommend calling qError to get extended error information. @qSuccess & @qSuccessInfo are WIL constants defined in the ODBC extender help file. Reference:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WIL~Extenders/ODBC+ODBC~Extender~with~WebBatch~problems.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

mpiaser

That was helpful.  qError is giving me a message that there is a SQL Server Login error.  I entered a userid/password in the DSN and it works when I run the DSN Test function.  Although the example code doesn't provide for a userid/password, I wonder if I need to be providing the userid/password in Winbatch.

mpiaser

Problem has been solved.  I had to use Windows Authorization to SQL Server and I had to create a 32 bit DSN using \windows\SysWoW64\odbcad32.exe - note that I had to actually use the Run comment using the path and exe name.  When I tried using search for odbcad32.exe it did not work.

Deana

Thank you for sharing your solution.
Deana F.
Technical Support
Wilson WindowWare Inc.