Question Catching errors on database connection

jrhbright

New member
Joined
Sep 22, 2010
Messages
3
Programming Experience
Beginner
I'm not 100% sure if this is in the correct place but here goes anyway...

I have developed a windows forms application in vb.net 4 which connects to a MSSQL database. I have used the built-in tools to add the data source, data connection and data set. (Data->add new data source-> etc.)

The application is installed on staff laptops which may or may not have network connectivity and may or may not be able to access the server on which the database is held. Obviously this is causing unhandled errors when the program starts and tries to make a connection to the database. (using windows credentials)

Does anyone know where in the code the connection is made so I can go in and add some error handling? Or any settings I can change to get visual studio to handle the errors nicely?

Thanks.
 
.Fill method of the DataAdapter should be where your exception occurs. Put a try block around that method and catch the SQLException and you should have all of the information you need in the SQLException object:

VB.NET:
Try
   DataAdapter.Fill(DataSet)
Catch Ex as SqlClient.SqlException
   'There are plenty of other properties with valuable information in them as well
   MessageBox.Show(Ex.Message)
End Try
 
Back
Top