本文整理汇总了C#中System.Data.Odbc.OdbcException类的典型用法代码示例。如果您正苦于以下问题:C# OdbcException类的具体用法?C# OdbcException怎么用?C# OdbcException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OdbcException类属于System.Data.Odbc命名空间,在下文中一共展示了OdbcException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowOdbcException
public void ShowOdbcException()
{
string mySelectQuery = "SELECT column1 FROM table1";
OdbcConnection myConnection =
new OdbcConnection("DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;");
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (OdbcException e)
{
string errorMessages = "";
for (int i=0; i < e.Errors.Count; i++)
{
errorMessages += "Index #" + i + "\n" +
"Message: " + e.Errors[i].Message + "\n" +
"NativeError: " + e.Errors[i].NativeError.ToString() + "\n" +
"Source: " + e.Errors[i].Source + "\n" +
"SQL: " + e.Errors[i].SQLState + "\n";
}
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(errorMessages);
Console.WriteLine("An exception occurred. Please contact your system administrator.");
}
}