Get more info from sqlclient error message
-
23-06-2021 - |
Question
I connect my windows mobile app directly to ms-sql server using the sqlclient dll from microsoft. Some times I get this error when trying to get some data from the server:
System.Data.SqlClient.SqlException: SqlException
at System.Data.SqlClient.SqlConnection.OnError()
at System.Data.SqlClient.SqlInternalConnection.OnError()
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run()
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at System.Data.SqlClient.SqlCommand.ExecuteReader()
Every time I have a error like this I need to try a few other things, some times the connection string is no good, or the network is not configured right or any other random problem.
Is there a way I could get a bit more info from the program so I shouldn't have to waste a few hours figuring out what might went rung?
Solution 2
Ok I found the answer... I changed: Catch ex As Exception
To: Catch ex As SqlException
Now I get the specific error nicely displayed in the message.
OTHER TIPS
That's basically just the stack trace. You should be able to get the Message
property of the SqlException
which contains the details. In some cases you will have to look at the InnerException
to get to the interesting details.