Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Testing connection to SQL Server
Message
 
 
To
23/12/2022 13:52:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01685573
Message ID:
01685604
Views:
28
>>>Hi,
>>>
>>>Sorry for creating too many threads about somewhat of the same problem/solution.
>>>
>>>I have been thinking and analyzing my code, none stop, every waking hour. And I just realized why I am not seeing the results I expect.
>>>In a nutshell:
>>>The application method CONN_HANDLE_ACCESS fires to check if SQLEXE() works. The code is literally like this:
>>>
>>>IF SQLEXEC( oApp.conn_handle, "") < 0 
>>>
>>>But the above only tests if an empty string can be executed.
>>>
>>>Often times, after the above code, the program fails when attempting to SQL Select some records from the SQL Server.
>>>
>>>So, I am thinking that the code of testing SQLEXEC() against an empty string, should be changed to testing SQLEXEC() against something in the SQL Server. Because, if the connection to the SQL Server is broken, the SQLEXEC() can still successfully work on an empty string. Right?
>>>
>>>If the above logic is correct, how do I change the test of SQLEXEC() NOT against an empty string but against something in the SQL Server?
>>>
>>>Any suggestions or input? TIA
>>
>>In my attempts to resolve this problem:
>>
>>
>>Connectivity error: [Microsoft][ODBC SQL Server Driver]Communication link failure 
>>
>>
>>I was thinking: what if I wrap the call the SQLEXEC() into a do while and try it for, say 2-3 seconds? Just to see if maybe the error happens because of some intermittent problem with the network card?
>>
>>Has anybody tried this approach? (trying SQLEXEC() for 2-3 seconds, before giving up)?
>>
>>TIA
>
>Hi Dmitry!
>"The Communication Link failure" is exact our Szenario we fixed. Yes you can wrap it in a while-loop and wait for some seconds.
>And you can present the User a "Connection ist broken. Trying to reconnect..." Message, if you want. We do so..
>
>I can't post our code here, bud the essential things:
>
>...
>* test SQL Connection
>if sqlexec(lnConnectionHandle, []) >=0
>  * Everything is fine
>else
>  * now check aError
>  aerror(laError)
>  if m.laError[1,1] = 1526
>     * It is an SQL Connection error, now a look at the 5. Column can give us Details
>     do case
>          case  laError[1,5] = 229
>              * Connection error!
>              * Now first you have do make all sql Handles idle
>               asqlhandles(laSqlhndls)
>               for each m.lnOdbchdbc IN m.laSqlhndls foxobject 
>                     sqlIdleDisconnect(m.lnOdbchdbc)
>               endfor
>
>              * And now, try again to check the SQL Connection
>               if sqlexec(lnConnectionHandle, []) >=0
>                 * Everything is fine
>               else
>                 * now check aError again.... --> Ok, you have to put everything in a Loop, an we show the User a Message "Connetion is broken, wait until it workes again"... aso.
>          case inlist(laError[1,5], 1205, 1222) 
>              * Deadlock or Lock occured, you have to Deal with it...
>    endcase
>  endif
>endif
>
When testing the application connection to the SQL Server, I have code almost exactly matching your code. But I will double check to see if I am missing anything.
Thank you!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform