I'm guessing that either the connection was not established to begin with or it was lost somehow since it was established. What do you do to establish the connection
Do you use SQLCONNECT( ) or SQLSTRINGCONNECT( ) to establish connection If so, do you check whether the connection is established by verifying that the Handle >0. Or do you lose the connection that was once established and worked properly
Something like:
PUBLIC lnConnHandle
LOCAL lcServerName, lcSQLUserID, lcSQLPassword, lcSQLUserID, lcSQLPassword, lcSQLDBName
*--Verify the values of all parameters passed by setting them yourself
lcSQLUSerID = 'MySQLId'
lcUserId = ''
lcConsole = ''
lcSQLPassword = "MyPassword"
lcservername = "Myserver"
lcSQLdbName = "MyDbName"
lcProgName = 'MyProgramName'
lcConnString = "DRIVER={SQL Server};" ;
+ "Server=" + lcServerName + ";" ;
+ IIF(EMPTY(lcSQLUserID) AND EMPTY(lcSQLPassword),"","UID=" +lcSQLUserID+ ";" ;
+ "PWD=" + lcSQLPassword + ";") ;
+ "DATABASE=" + lcSQLDBName + ;
+ IIF(TYPE('lcProgName') = "C",";" ;
+ "APP=" + lcProgName + IIF(TYPE('lcConsole')="C", " " + lcConSole,"") + ;
IIF(TYPE('lcUserId')="C", " " + TRIM(lcUserId),""),"")
lnConnHandle = SQLSTRINGCONNECT(lcConnString)
"Connection handle:"
lnconnhandle
IF lnConnHandle > 0 then
MESSAGEBOX ("Connection Successful")
=SQLDISCONNECT(lnConnHandle)
ELSE
=MESSAGEBOX ("Connection Failed")
RETURN
ENDIF
|