System.Data.SqlClient.SqlException.CreateException C# (CSharp) Method

CreateException() static private method

static private CreateException ( SqlErrorCollection errorCollection, string serverVersion, System.Guid conId, Exception innerException = null ) : SqlException
errorCollection SqlErrorCollection
serverVersion string
conId System.Guid
innerException System.Exception
return SqlException
        static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
        {
            Debug.Assert(null != errorCollection && errorCollection.Count > 0, "no errorCollection?");

            StringBuilder message = new StringBuilder();
            for (int i = 0; i < errorCollection.Count; i++)
            {
                if (i > 0)
                {
                    message.Append(Environment.NewLine);
                }
                message.Append(errorCollection[i].Message);
            }

            if (innerException == null && errorCollection[0].Win32ErrorCode != 0 && errorCollection[0].Win32ErrorCode != -1)
            {
                innerException = new Win32Exception(errorCollection[0].Win32ErrorCode);
            }

            SqlException exception = new SqlException(message.ToString(), errorCollection, innerException, conId);

            exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server");

            if (!string.IsNullOrEmpty(serverVersion))
            {
                exception.Data.Add("HelpLink.ProdVer", serverVersion);
            }
            exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer");
            exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
            exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
            exception.Data.Add("HelpLink.LinkId", "20476");

            return exception;
        }

Same methods

SqlException::CreateException ( SqlErrorCollection errorCollection, string serverVersion ) : SqlException
SqlException::CreateException ( SqlErrorCollection errorCollection, string serverVersion, System.Data.SqlClient.SqlInternalConnectionTds internalConnection, Exception innerException = null ) : SqlException

Usage Example

Example #1
0
        internal static Exception CannotCompleteDelegatedTransactionWithOpenResults()
        {
            SqlErrorCollection errorCollection = new SqlErrorCollection();

            errorCollection.Add(new SqlError(-2, 0, 11, null, Res.GetString("ADP_OpenReaderExists"), "", 0));
            return(SqlException.CreateException(errorCollection, null));
        }
All Usage Examples Of System.Data.SqlClient.SqlException::CreateException