1 //------------------------------------------------------------------------------
2 // <copyright file="OdbcException.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
10 using System
.ComponentModel
; //Component
11 using System
.Collections
; //ICollection
13 using System
.Data
.Common
;
14 using System
.Globalization
;
15 using System
.Runtime
.InteropServices
;
16 using System
.Runtime
.Serialization
;
19 namespace System
.Data
.Odbc
{
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
);
40 internal OdbcException(string message
, OdbcErrorCollection errors
) : base(message
) {
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
{
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
) {
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
{
72 if (0 < Errors
.Count
) {
73 string source
= Errors
[0].Source
;
74 return ADP
.IsEmpty(source
) ? "" : source
; // base.Source;
76 return ""; // base.Source;