本文整理汇总了C#中System.Data.SqlClient.SqlException.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlException.ToString方法的具体用法?C# SqlException.ToString怎么用?C# SqlException.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlException
的用法示例。
在下文中一共展示了SqlException.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TranslateSQLException
/// <summary>
/// function to translate sql exceptions to readable messages.
/// It also captures cases where sql server is not available and guards against
/// database connection details being leaked
/// </summary>
/// <param name = "exc"></param>
/// <returns></returns>
/// <remarks>
/// </remarks>
public static string TranslateSQLException(SqlException exc)
{
int i = 0;
var errorMessages = new StringBuilder();
for (i = 0; i <= exc.Errors.Count - 1; i++)
{
SqlError sqlError = exc.Errors[i];
string filteredMessage = string.Empty;
switch (sqlError.Number)
{
case 17:
filteredMessage = "Sql server does not exist or access denied";
break;
case 4060:
filteredMessage = "Invalid Database";
break;
case 18456:
filteredMessage = "Sql login failed";
break;
case 1205:
filteredMessage = "Sql deadlock victim";
break;
default:
filteredMessage = exc.ToString();
break;
}
errorMessages.Append("<b>Index #:</b> " + i + "<br/>" + "<b>Source:</b> " + sqlError.Source + "<br/>" + "<b>Class:</b> " + sqlError.Class + "<br/>" + "<b>Number:</b> " +
sqlError.Number + "<br/>" + "<b>Procedure:</b> " + sqlError.Procedure + "<br/>" + "<b>Message:</b> " + filteredMessage + "<br/>");
}
return errorMessages.ToString();
}
示例2: WriteToEventLog
private void WriteToEventLog(SqlException e, string action)
{
EventLog log = new EventLog();
log.Source = eventSource;
log.Log = eventLog;
string message = exceptionMessage + "\n\n";
message += "Action: " + action + "\n\n";
message += "Exception: " + e.ToString();
log.WriteEntry(message);
}
示例3: LogException
public static void LogException(SqlException exception)
{
if (exception != null)
{
Debug.Print(exception.ToString());
Logger.Error(exception.ToString());
try
{
/* All SQL errors must be logged */
var error = new VLogServerSideSqlError(exception);
if (VLog.OnCommitExceptionToServerRepository != null)
{
VLog.OnCommitExceptionToServerRepository(error);
}
}
catch (Exception ex)
{
// IMPORTANT! We swallow any exception raised during the
// logging and send them out to the trace . The idea
// here is that logging of exceptions by itself should not
// be critical to the overall operation of the application.
// The bad thing is that we catch ANY kind of exception,
// even system ones and potentially let them slip by.
Logger.Error(ex.ToString());
Debug.Print(ex.Message);
}
}
}
示例4: InternalHandle
/// <summary>
/// Internals the handle.
/// </summary>
/// <param name="ex">The executable.</param>
/// <returns></returns>
private ErrorAction InternalHandle(SqlException ex)
{
return new ErrorAction(ErrorActionType.Retry, -2147220970, ex.ToString());
}