PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → WD22 - Sqlserver reconnect
WD22 - Sqlserver reconnect
Débuté par Arie, 30 mar. 2018 21:05 - 5 réponses
Posté le 30 mars 2018 - 21:05
Hi,

I facing a situtation where HOpenConnection() does NOT return false even when there is no connection possible to the database. It look like some kind of cache problem or something like that.

First time I open a connection
I run some querys and so to present info to users on a big screen
Then I close the connection

Every 30 seconds the info is refresh using a timer. Again, HOpenConnection, show data, HCloseConnection.

Now I unplug the network. Wait for the next timer loop and then HOpenConnection still returns TRUE, indicating the connection is open?!?!
Also a HOpen(Tbl_License) returns TRUE.
However using the first real data access with HReadFirst there is finally an error. See below.

Why doesn't HOpenConnection return FALSE ??
native SQLSERVER access error.
Error Number = 117

Unable to open or read file.

Error 80004005 returned by SQL Server
Description: Deferred prepare could not be completed.
SQL State:
SQL Error Number: 0

Sub-error #1
Description: Unable to open a logical session
SQL State: 08S02
SQL Error Number: -1

Sub-error #2
Description: SMux Provider: Physical connection is not usable
Posté le 30 mars 2018 - 21:34
Hi Arie,

I'm GUESSING here... But based on the error message content: "Deferred prepare..." - "...Physical connection is not usable" I would say that in this situation the LOCAL dll (native access) is optimizing (or trying to) the access by deferring the REAL PHYSICAL opening of the file to the time when you try to access data...

Hence the error only when you are doing that...

Now, is that an option of the MSSQL access? Maybe...

Otherwise, you'll just have to do a hreadfirst just after the hopenconnection to check.

Best regards
Posté le 30 mars 2018 - 22:32
Hello Arie

I ran into this year's ago I ended up opening a socket first to make sure there is a connection available then closed it. But in your case where you have to do it on a timer just trap the error of the read of the data file.
Posté le 02 avril 2018 - 20:02
Well, detecting the connection is broken or lost is not the problem. At the first point data is really read, you will get an error.

However if the physical connection is up and running again (network cable re-plugged in at some point) the connection from within my software still remains unuseable.

Same thing happens with the oledb driver instead of the native driver btw.

So HOpenConnection and HCloseConnection are more like a logical thing, which is not affected by an interrupt of the physical connection. Somewhere on the WD???.DLL level the connection remains there and a subsequent HOpenConnection "hooks" itself into that one everytime?

Still a bit strange, because when I end my software and restart it again, THEN the connection problems ARE detected of course.

In C# I would set the conneciotn-object to null, to really destroy it. But Windev does not allow me to do such things in W-Language.
Posté le 03 avril 2018 - 15:15
Arie

Have you tried VariableReset(MyConnection) before HOpenConnection() ?

VariableReset() sets all values of the variable to their defaults so may possibly reset the result of the previous connection request as well.
Depends I guess on where this seemingly persistent value resides.

Just thinking out loud so not actually tested this but it may be worth looking at.
Posté le 10 avril 2018 - 10:17
Hi Derek,

finally had some time to test this and it seems to help! This function does some black magic with the variable indeed.
Thank for the tip.