File: SqlError.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (101 lines) | stat: -rw-r--r-- 3,890 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//------------------------------------------------------------------------------
// <copyright file="SqlError.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------

namespace System.Data.SqlClient {

    using System;
    using System.Diagnostics;
    using System.Globalization;

    [Serializable]
    public sealed class SqlError {

        // bug fix - MDAC 48965 - missing source of exception
        // fixed by Microsoft
        private string source = TdsEnums.SQL_PROVIDER_NAME;
        private int    number;
        private byte   state;
        private byte   errorClass;
        [System.Runtime.Serialization.OptionalFieldAttribute(VersionAdded=2)]
        private string server;
        private string message;
        private string procedure;
        private int    lineNumber;
        [System.Runtime.Serialization.OptionalFieldAttribute(VersionAdded=4)]
        private int win32ErrorCode;

        internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber, uint win32ErrorCode)
            : this(infoNumber, errorState, errorClass, server, errorMessage, procedure, lineNumber)
        {
            this.win32ErrorCode = (int)win32ErrorCode;
        }

        internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber) {
            this.number = infoNumber;
            this.state = errorState;
            this.errorClass = errorClass;
            this.server = server;
            this.message = errorMessage;
            this.procedure = procedure;
            this.lineNumber = lineNumber;
            if (errorClass != 0) {
                Bid.Trace("<sc.SqlError.SqlError|ERR> infoNumber=%d, errorState=%d, errorClass=%d, errorMessage='%ls', procedure='%ls', lineNumber=%d\n" ,
                    infoNumber, (int)errorState, (int)errorClass,  errorMessage,
                    procedure == null ? "None" : procedure, (int)lineNumber);
            }
            this.win32ErrorCode = 0;
        }

        // bug fix - MDAC #49280 - SqlError does not implement ToString();
        // I did not include an exception stack because the correct exception stack is only available 
        // on SqlException, and to obtain that the SqlError would have to have backpointers all the
        // way back to SqlException.  If the user needs a call stack, they can obtain it on SqlException.
        public override string ToString() {
            //return this.GetType().ToString() + ": " + this.message;
            return typeof(SqlError).ToString() + ": " + this.message; // since this is sealed so we can change GetType to typeof
        }

        // bug fix - MDAC #48965 - missing source of exception
        // fixed by Microsoft
        public string Source {
            get { return this.source;}
        }

        public int Number {
            get { return this.number;}
        }

        public byte State {
            get { return this.state;}
        }

        public byte Class {
            get { return this.errorClass;}
        }

        public string Server {
            get { return this.server;}
        }

        public string Message {
            get { return this.message;}
        }

        public string Procedure {
            get { return this.procedure;}
        }

        public int LineNumber {
            get { return this.lineNumber;}
        }

        internal int Win32ErrorCode {
            get { return this.win32ErrorCode; }
        }
    }
}