当前位置: 首页>>代码示例>>C#>>正文


C# SqlException.ToString方法代码示例

本文整理汇总了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();
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:41,代码来源:SqlUtils.cs

示例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);
    }
开发者ID:WFPVAM,项目名称:GRASPReporting,代码行数:12,代码来源:CustomRoleProvider.cs

示例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);
                }
            }
        }
开发者ID:MGramolini,项目名称:vodca,代码行数:30,代码来源:VLog.LogException.cs

示例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());
 }
开发者ID:udbeeq5566,项目名称:ESB,代码行数:9,代码来源:SqlErrorHandler.cs


注:本文中的System.Data.SqlClient.SqlException.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。