FUNCTION TestSqlQuery AS VOID
VAR connString = "driver={Sql Server}; server=192.168.X.XXSQLEXPRESS; database=XXXX; uid=XXXX; pwd=XXXX;"
VAR nHandle = SqlStringConnect(connString)
VAR cSql = "Select * From Customers Order by CustomerNo"
VAR nResult = SqlExec(nHandle, cSql, "csrSqlQuery1")
FIELD CustomerNo, Company && Add this to make compiler happy when we reference field names in Scan statement.
SCAN
? CustomerNo + ": " + Company
ENDSCAN
ENDFUNC
1. I'm using 2.20.0.3 and SQLEXEC() always returns -1 even when the query is ok. @robert Is that a bug?
2. SQLEXEC() just works with the old SQL Server driver, I'm testing it against the following drivers:
1. SQL Server -> Works
2. SQL Server Native Client 10.0 -> Does not work
3. SQL Server Native Client 11.0 -> Does not work
4. ODBC Driver 17 for SQL Server -> Does not work
LOCAL lnHandle := SQLSTRINGCONNECT("Driver={SQL Server};Server=the_server;Database=the_db;Uid=sa;Pwd=secret;") AS LONG
IF lnHandle > 0
TRY
VAR lnResult := SQLEXEC(lnHandle, "SELECT top 10 * FROM sometable", "cursor1")
? lnResult // this is always -1 even when the query is ok.
SCAN
? i"{cursor1.field1}"
ENDSCAN
CATCH TO loEx
?loEx.Message
FINALLY
SQLDISCONNECT(lnHandle)
CLOSE
END TRY
ENDIF