Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data / System / Data / Odbc / OdbcException.cs
bloba852637eb52b17adaaf4fdc6634adea3d5e6f8b3
1 //------------------------------------------------------------------------------
2 // <copyright file="OdbcException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 using System;
10 using System.ComponentModel; //Component
11 using System.Collections; //ICollection
12 using System.Data;
13 using System.Data.Common;
14 using System.Globalization;
15 using System.Runtime.InteropServices;
16 using System.Runtime.Serialization;
17 using System.Text;
19 namespace System.Data.Odbc {
21 [Serializable]
22 public sealed class OdbcException : System.Data.Common.DbException {
23 OdbcErrorCollection odbcErrors = new OdbcErrorCollection();
25 ODBC32.RETCODE _retcode; // DO NOT REMOVE! only needed for serialization purposes, because Everett had it.
27 static internal OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode) {
28 StringBuilder builder = new StringBuilder();
29 foreach (OdbcError error in errors) {
30 if (builder.Length > 0) {
31 builder.Append(Environment.NewLine);
34 builder.Append(Res.GetString(Res.Odbc_ExceptionMessage, ODBC32.RetcodeToString(retcode), error.SQLState, error.Message)); // MDAC 68337
36 OdbcException exception = new OdbcException(builder.ToString(), errors);
37 return exception;
40 internal OdbcException(string message, OdbcErrorCollection errors) : base(message) {
41 odbcErrors = errors;
42 HResult = HResults.OdbcException;
45 // runtime will call even if private...
46 private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) {
47 _retcode = (ODBC32.RETCODE) si.GetValue("odbcRetcode", typeof(ODBC32.RETCODE));
48 odbcErrors = (OdbcErrorCollection) si.GetValue("odbcErrors", typeof(OdbcErrorCollection));
49 HResult = HResults.OdbcException;
52 public OdbcErrorCollection Errors {
53 get {
54 return odbcErrors;
58 [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
59 override public void GetObjectData(SerializationInfo si, StreamingContext context) {
60 // MDAC 72003
61 if (null == si) {
62 throw new ArgumentNullException("si");
64 si.AddValue("odbcRetcode", _retcode, typeof(ODBC32.RETCODE));
65 si.AddValue("odbcErrors", odbcErrors, typeof(OdbcErrorCollection));
66 base.GetObjectData(si, context);
69 // mdac bug 62559 - if we don't have it return nothing (empty string)
70 override public string Source {
71 get {
72 if (0 < Errors.Count) {
73 string source = Errors[0].Source;
74 return ADP.IsEmpty(source) ? "" : source; // base.Source;
76 return ""; // base.Source;