Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Data / System / Data / OleDb / OleDbException.cs / 1 / OleDbException.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.OleDb { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data.Common; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Text; [Serializable] #if WINFSInternalOnly internal #else public #endif sealed class OleDbException : System.Data.Common.DbException { private OleDbErrorCollection oledbErrors; internal OleDbException(string message, OleDbHResult errorCode, Exception inner) : base(message, inner) { HResult = (int)errorCode; this.oledbErrors = new OleDbErrorCollection(null); } internal OleDbException(OleDbException previous, Exception inner) : base(previous.Message, inner) { HResult = previous.ErrorCode; this.oledbErrors = previous.oledbErrors; } private OleDbException(string message, Exception inner, string source, OleDbHResult errorCode, OleDbErrorCollection errors) : base(message, inner) { // MDAC 84364 Debug.Assert(null != errors, "OleDbException without OleDbErrorCollection"); Source = source; HResult = (int)errorCode; this.oledbErrors = errors; } // runtime will call even if private... private OleDbException(SerializationInfo si, StreamingContext sc) : base(si, sc) { oledbErrors = (OleDbErrorCollection) si.GetValue("oledbErrors", typeof(OleDbErrorCollection)); } [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] override public void GetObjectData(SerializationInfo si, StreamingContext context) { // MDAC 72003 if (null == si) { throw new ArgumentNullException("si"); } si.AddValue("oledbErrors", oledbErrors, typeof(OleDbErrorCollection)); base.GetObjectData(si, context); } [ TypeConverterAttribute(typeof(ErrorCodeConverter)) ] override public int ErrorCode { get { return base.ErrorCode; } } [ DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public OleDbErrorCollection Errors { get { OleDbErrorCollection errors = this.oledbErrors; return ((null != errors) ? errors : new OleDbErrorCollection(null)); } } internal bool ShouldSerializeErrors() { // MDAC 65548 OleDbErrorCollection errors = this.oledbErrors; return ((null != errors) && (0 < errors.Count)); } static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) { // MDAC 84364 OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo); string message = null; string source = null; OleDbHResult hr = 0; if (null != errorInfo) { hr = errorInfo.GetDescription(out message); Bid.Trace("%08X{HRESULT}, Description='%ls'\n", hr, message); hr = errorInfo.GetSource(out source); Bid.Trace(" %08X{HRESULT}, Source='%ls'\n", hr, source); } int count = errors.Count; if (0 < errors.Count) { StringBuilder builder = new StringBuilder(); if ((null != message) && (message != errors[0].Message)) { // WebData 103032 builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 if (1 < count) { builder.Append(Environment.NewLine); } } for (int i = 0; i < count; ++i) { if (0 < i) { builder.Append(Environment.NewLine); } builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 } message = builder.ToString(); } if (ADP.IsEmpty(message)) { message = ODB.NoErrorMessage(errorCode); // MDAC 71170 } return new OleDbException(message, inner, source, errorCode, errors); } static internal OleDbException CombineExceptions(List exceptions) { Debug.Assert(0 < exceptions.Count, "missing exceptions"); if (1 < exceptions.Count) { OleDbErrorCollection errors = new OleDbErrorCollection(null); StringBuilder builder = new StringBuilder(); foreach(OleDbException exception in exceptions) { errors.AddRange(exception.Errors); builder.Append(exception.Message); builder.Append(Environment.NewLine); } return new OleDbException(builder.ToString(), null, exceptions[0].Source, (OleDbHResult)exceptions[0].ErrorCode, errors); } else { return exceptions[0]; } } sealed internal class ErrorCodeConverter : Int32Converter { // MDAC 68557 // converter classes should have public ctor public ErrorCodeConverter() { } override public object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw ADP.ArgumentNull("destinationType"); } if ((destinationType == typeof(string)) && (value != null) && (value is Int32)) { return ODB.ELookup((OleDbHResult) value); } return base.ConvertTo(context, culture, value, destinationType); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.OleDb { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data.Common; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Text; [Serializable] #if WINFSInternalOnly internal #else public #endif sealed class OleDbException : System.Data.Common.DbException { private OleDbErrorCollection oledbErrors; internal OleDbException(string message, OleDbHResult errorCode, Exception inner) : base(message, inner) { HResult = (int)errorCode; this.oledbErrors = new OleDbErrorCollection(null); } internal OleDbException(OleDbException previous, Exception inner) : base(previous.Message, inner) { HResult = previous.ErrorCode; this.oledbErrors = previous.oledbErrors; } private OleDbException(string message, Exception inner, string source, OleDbHResult errorCode, OleDbErrorCollection errors) : base(message, inner) { // MDAC 84364 Debug.Assert(null != errors, "OleDbException without OleDbErrorCollection"); Source = source; HResult = (int)errorCode; this.oledbErrors = errors; } // runtime will call even if private... private OleDbException(SerializationInfo si, StreamingContext sc) : base(si, sc) { oledbErrors = (OleDbErrorCollection) si.GetValue("oledbErrors", typeof(OleDbErrorCollection)); } [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] override public void GetObjectData(SerializationInfo si, StreamingContext context) { // MDAC 72003 if (null == si) { throw new ArgumentNullException("si"); } si.AddValue("oledbErrors", oledbErrors, typeof(OleDbErrorCollection)); base.GetObjectData(si, context); } [ TypeConverterAttribute(typeof(ErrorCodeConverter)) ] override public int ErrorCode { get { return base.ErrorCode; } } [ DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public OleDbErrorCollection Errors { get { OleDbErrorCollection errors = this.oledbErrors; return ((null != errors) ? errors : new OleDbErrorCollection(null)); } } internal bool ShouldSerializeErrors() { // MDAC 65548 OleDbErrorCollection errors = this.oledbErrors; return ((null != errors) && (0 < errors.Count)); } static internal OleDbException CreateException(UnsafeNativeMethods.IErrorInfo errorInfo, OleDbHResult errorCode, Exception inner) { // MDAC 84364 OleDbErrorCollection errors = new OleDbErrorCollection(errorInfo); string message = null; string source = null; OleDbHResult hr = 0; if (null != errorInfo) { hr = errorInfo.GetDescription(out message); Bid.Trace("%08X{HRESULT}, Description='%ls'\n", hr, message); hr = errorInfo.GetSource(out source); Bid.Trace(" %08X{HRESULT}, Source='%ls'\n", hr, source); } int count = errors.Count; if (0 < errors.Count) { StringBuilder builder = new StringBuilder(); if ((null != message) && (message != errors[0].Message)) { // WebData 103032 builder.Append(message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 if (1 < count) { builder.Append(Environment.NewLine); } } for (int i = 0; i < count; ++i) { if (0 < i) { builder.Append(Environment.NewLine); } builder.Append(errors[i].Message.TrimEnd(ODB.ErrorTrimCharacters)); // MDAC 73707 } message = builder.ToString(); } if (ADP.IsEmpty(message)) { message = ODB.NoErrorMessage(errorCode); // MDAC 71170 } return new OleDbException(message, inner, source, errorCode, errors); } static internal OleDbException CombineExceptions(List exceptions) { Debug.Assert(0 < exceptions.Count, "missing exceptions"); if (1 < exceptions.Count) { OleDbErrorCollection errors = new OleDbErrorCollection(null); StringBuilder builder = new StringBuilder(); foreach(OleDbException exception in exceptions) { errors.AddRange(exception.Errors); builder.Append(exception.Message); builder.Append(Environment.NewLine); } return new OleDbException(builder.ToString(), null, exceptions[0].Source, (OleDbHResult)exceptions[0].ErrorCode, errors); } else { return exceptions[0]; } } sealed internal class ErrorCodeConverter : Int32Converter { // MDAC 68557 // converter classes should have public ctor public ErrorCodeConverter() { } override public object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw ADP.ArgumentNull("destinationType"); } if ((destinationType == typeof(string)) && (value != null) && (value is Int32)) { return ODB.ELookup((OleDbHResult) value); } return base.ConvertTo(context, culture, value, destinationType); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityCommandDefinition.cs
- Fonts.cs
- Message.cs
- HttpListenerElement.cs
- FrameworkContentElementAutomationPeer.cs
- PropertyChangedEventManager.cs
- ParentQuery.cs
- CalculatedColumn.cs
- BackgroundFormatInfo.cs
- DropShadowBitmapEffect.cs
- BaseAddressPrefixFilterElementCollection.cs
- RelatedEnd.cs
- DataServiceBuildProvider.cs
- XmlNodeChangedEventManager.cs
- HttpApplication.cs
- FontStyleConverter.cs
- ParameterBinding.cs
- DemultiplexingDispatchMessageFormatter.cs
- _HTTPDateParse.cs
- DataGridRowsPresenter.cs
- ConcatQueryOperator.cs
- DataGridViewRowEventArgs.cs
- InstanceKeyCompleteException.cs
- DataKeyCollection.cs
- CellLabel.cs
- BaseProcessProtocolHandler.cs
- TemplateEditingFrame.cs
- ScrollPattern.cs
- DatatypeImplementation.cs
- OutOfMemoryException.cs
- Token.cs
- NotifyIcon.cs
- SystemThemeKey.cs
- Brush.cs
- ContextStaticAttribute.cs
- DataDesignUtil.cs
- UIPropertyMetadata.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- RenderDataDrawingContext.cs
- MbpInfo.cs
- ObjectConverter.cs
- WebPartCatalogAddVerb.cs
- DropShadowEffect.cs
- HttpCachePolicyBase.cs
- HttpCapabilitiesBase.cs
- DebugView.cs
- MLangCodePageEncoding.cs
- FunctionParameter.cs
- TextOptions.cs
- DocumentViewerAutomationPeer.cs
- InputLanguageCollection.cs
- StoragePropertyMapping.cs
- DataAdapter.cs
- DataFormat.cs
- StandardToolWindows.cs
- EnlistmentTraceIdentifier.cs
- XmlSchemaImport.cs
- ControlEvent.cs
- MethodSignatureGenerator.cs
- CapabilitiesRule.cs
- AlternateView.cs
- BezierSegment.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- ObjectPropertyMapping.cs
- AnnotationStore.cs
- AspNetRouteServiceHttpHandler.cs
- RangeEnumerable.cs
- IndividualDeviceConfig.cs
- WebPartCatalogCloseVerb.cs
- OracleConnectionFactory.cs
- XmlReader.cs
- VisualTreeUtils.cs
- Types.cs
- UTF7Encoding.cs
- BorderGapMaskConverter.cs
- EmptyCollection.cs
- ManagementOptions.cs
- DependencySource.cs
- MergablePropertyAttribute.cs
- InvokePattern.cs
- SyndicationSerializer.cs
- DirectoryInfo.cs
- TabControlAutomationPeer.cs
- CharEnumerator.cs
- LocatorManager.cs
- LocatorManager.cs
- InternalsVisibleToAttribute.cs
- SourceLocation.cs
- ComponentResourceManager.cs
- DataGridViewCheckBoxCell.cs
- arabicshape.cs
- UITypeEditor.cs
- UIElementAutomationPeer.cs
- IndexingContentUnit.cs
- InputLanguage.cs
- ZipIOExtraFieldZip64Element.cs
- AutomationEventArgs.cs
- ExtensibleClassFactory.cs
- CatalogZoneBase.cs
- AllMembershipCondition.cs