viewpoint-particle

Author Topic: ODBC QConnect  (Read 5916 times)

mpiaser

  • Newbie
  • *
  • Posts: 26
ODBC QConnect
« on: June 22, 2013, 07:22:59 am »
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

  • Pundit
  • *****
  • Posts: 939
Re: ODBC QConnect
« Reply #1 on: June 22, 2013, 07:51:43 am »
I replied on old board.

mpiaser

  • Newbie
  • *
  • Posts: 26
Re: ODBC QConnect
« Reply #2 on: June 22, 2013, 08:59:52 am »
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

  • Pundit
  • *****
  • Posts: 939
Re: ODBC QConnect
« Reply #3 on: June 22, 2013, 09:22:35 am »
Not sure about those properties, but normally in ODBC/ADO/OLEDB 0=False and non-zero=True (normally 1 or -1).
 

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: ODBC QConnect
« Reply #4 on: June 22, 2013, 09:31:05 am »
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

  • Newbie
  • *
  • Posts: 26
Re: ODBC QConnect
« Reply #5 on: June 22, 2013, 09:50:20 am »
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

  • Newbie
  • *
  • Posts: 26
Re: ODBC QConnect
« Reply #6 on: June 23, 2013, 08:22:53 am »
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

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: ODBC QConnect
« Reply #7 on: June 23, 2013, 04:09:46 pm »
Thank you for sharing your solution.
Deana F.
Technical Support
Wilson WindowWare Inc.