[英]Get more info from sqlclient error message
I connect my windows mobile app directly to ms-sql server using the sqlclient dll from microsoft. 我使用Microsoft的sqlclient dll将Windows Mobile应用程序直接连接到ms-sql服务器。 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? 有什么办法可以从程序中获取更多信息,这样我就不必浪费几个小时弄清楚什么可能会响起来吗?
That's basically just the stack trace. 基本上,这只是堆栈跟踪。 You should be able to get the Message
property of the SqlException
which contains the details. 您应该能够获取包含详细信息的SqlException
的Message
属性。 In some cases you will have to look at the InnerException
to get to the interesting details. 在某些情况下,您将不得不查看InnerException
以获得有趣的细节。
Ok I found the answer... I changed: Catch ex As Exception
To: Catch ex As SqlException
好的,我找到了答案...我改变了:将Catch ex As Exception
Catch ex As SqlException
为:将Catch ex As Exception
Catch ex As SqlException
Now I get the specific error nicely displayed in the message. 现在,我在消息中很好地显示了特定错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.