Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a app vb.net that its database is on server and app is under net i want when user clicks on the button of form the program check and if server is off or close the message box show
the problem is that server name and username and pass of server may be change can i write some code that check server connection
by the way I write sub that create connection string dynamically and save it in xml file and when load form the connection string created but i don't know how check connection state of server
Posted
Updated 17-Aug-15 13:06pm
v2

1 solution

Connection to what kind of server?

Most of the time, the only way to "check the connection" is to try and connect and see if it comes back with any exceptions.
 
Share this answer
 
Comments
rezaeti 18-Aug-15 10:41am    
mt database is sql server
rezaeti 18-Aug-15 10:42am    
my database is sql server
Dave Kreskowiak 18-Aug-15 10:53am    
OK, so the only way to know if the connection is going to work is to connect and handle any exceptions that get thrown. It's pretty much a waste of time to do anything different. Just because a connection works one time does not mean the connection is going to work 10 seconds from now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900