简体   繁体   English

从sqlclient错误消息获取更多信息

[英]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. 您应该能够获取包含详细信息的SqlExceptionMessage属性。 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.

相关问题 从运行WiN CE 6设备的C#.net CF 3.5向IBM Websphere MQ发送消息的最佳方法 - Best way to send message to IBM Websphere MQ from C# .net CF 3.5 running WiN CE 6 devices 尽管已在.NET CF 3.5的WM 6.5上成功发送消息,但SoapHttpClientProtocol仍引发ConnectFailure - SoapHttpClientProtocol throws ConnectFailure despite having successfully sent message on WM 6.5 with .NET CF 3.5 SQL Client错误在某些设备上却在其他设备上有效 - SQL Client error on some devices but works on other 在XP Embedded中运行.NET CF 3.5程序时出错 - Error running .NET CF 3.5 program in XP Embedded Sqlparameter.Dbtype.Xml在.NET Compact Framework中给出错误 - Sqlparameter.Dbtype.Xml giving error in .net compact framework 在VS 2008解决方案中添加了项目; 建立依赖性 获取编译器错误CS0246 - Added project to VS 2008 solution; created dependency; getting compiler error CS0246 如何调试在Windows CE 6的.NET CF 3.5 WinForms应用程序中调用Application.Exit()后发生的致命错误? - How to debug a fatal error that happens after calling Application.Exit() in .NET CF 3.5 WinForms application for Windows CE 6? Windows CE / Compact Framework 3.5上HttpWebRequest与RESTSharp上的RFC - RFC on HttpWebRequest vs RESTSharp from Windows CE / Compact Framework 3.5 在.NET Compact Framework 3.5中从GC获取调试数据 - Getting debug data from the GC in .NET Compact Framework 3.5 日期时间格式异常错误 - DateTime FormatException error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM