Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bad connection does not raise error event
Message
De
27/08/2002 18:53:57
 
 
À
26/08/2002 21:01:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00693801
Message ID:
00694275
Vues:
16
Hi John

I think you really nailed that one!
Thanks
Jim


>Hi James,
>
>As I read your code the error handler is not invoked because there is never an error. You tested for a valid connection handle with the following line:
>
>
>IF lnHandle < 1
>
>
>Even had you not done that an error would still not be invoked until later in code if you tried to use an SPT (SQL Pass Through) statetment, based on a bad conneciton handle, where you retrieved data and then tried to use the data from the results of the SPT statement.
>
>You have to test for a valid connection handle as you did. FoxPro really doesn't care if the connection was made or not.
>
>John
>
>
>>Hello Group,
>> When I pass a bad username and password to the following code I get the messagebox that "Connection Failed" but the error handler was not involked. When I send correct username and password it connects. Why isn't an error raised. I am reading Doug Hennig as we speak but it is sinking in slowly.
>>
>>Thanks
>>Jim
>>
>>lParam lcServer, lcUserID, lcPassword, lcDatabase
>>Local lnHandle,lcConnect
>>
>>ON ERROR DO ODBCErrorHandler
>>
>>lcConnect= "DRIVER={SQL Server};Server=" + lcServer + ";UID=" + lcUserID + ";PWD=" + lcPassword + ";Network=DBMSSOCN;" + "DATABASE=" + lcDatabase + ";"
>>
>>lnHandle = SQLSTRINGCONNECT(lcConnect)
>>
>>
>>IF lnHandle < 1 then && No Connection was made
>>
>> MESSAGEBOX("Connection Failed")
>> RETURN 0
>>
>>ELSE && connection made return the connection Handle
>>
>> RETURN lnHandle
>>
>>ENDIF
>>
>>ON ERROR
>>
>>PROCEDURE ODBCErrorHandler
>>LOCAL lcErrorString
>>
>>=AERROR(eray)
>>lcErrorString = "Error Number " + alltrim(str(eray(1)))
>>MessageBox(lcString)
>>
>>ENDPROC && ODBCErrorHandler
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform