In Delphi 7, how to quickly determine whether SQL can connect??
Thank you, everyone!!
With DM do
Begin
conn.connected: = False;
Conn.connectionstring: = connstring;
Try
conn.connected: = True;
Except
Application.messagebox (' Server connect error!! ', Cp_main,mb_oce);
End
End
You're just going to disconnect and reconnect if the SQL service is not turned on or it will be slow.
How to determine whether SQL connection, improve the speed of judgment???
You can set the Adoconnection.connectiontimeout to 1, which will be faster, or you can directly determine whether the SQL service is started (native).
Although the connection time is shortened, you will still find that the connection time is very slow during the test.
The key to this question is how fast do you want it? Second level? Millisecond level?
I think the millisecond level is impossible ...
Second-level words, but also depends on your local response time, server response time, network status, a second can be judged out of good. Want to be faster than impossible ah.
Set the adoconnection.connectiontimeout too small is not good, sometimes because of the server response time and network problems, can be connected for several seconds.
You can use port 1433 to determine whether the SQL service is stopped or linked
In Delphi 7, how to quickly determine whether SQL can connect??