Link to home
Start Free TrialLog in
Avatar of Mehawitchi
Mehawitchi

asked on

Is there a VB.Net code for testing connection to SQL Server database

Hello there,

I'm looking for a vb.net code that would test the connectivity to SQL Server database, in the same speed that happens when you establish a new connection using the wizard in VS 2005.

I want to be able to press a button in my VB application and I get a response ON THE SPOT that:
Connection is successfull or failed.

Appreciate any help,

Hani
Avatar of talker2004
talker2004
Flag of United States of America image

Yes you need to use the sqlconnection open method.

dim sqlconn as new sqlconnection(connectionstring)

try
sqlconn.open
msgbox "The connection is open"
catch
msgbox "Connection Failed"
finally
sqlconn.dispose
sqlconn=nothing
end try
Avatar of Mehawitchi
Mehawitchi

ASKER

Thanks talker2004.

Is this the common practice in my case?
ASKER CERTIFIED SOLUTION
Avatar of talker2004
talker2004
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again talker2004

This was so helpful