Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / SqlClient / SqlException.cs / 1305376 / SqlException.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.ComponentModel; using System.Data.Common; using System.Diagnostics; using System.Globalization; using System.Runtime.Serialization; using System.Text; // StringBuilder [Serializable] public sealed class SqlException : System.Data.Common.DbException { private SqlErrorCollection _errors; private SqlException(string message, SqlErrorCollection errorCollection) : base(message) { HResult = HResults.SqlException; _errors = errorCollection; } // runtime will call even if private... private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc) { _errors = (SqlErrorCollection) si.GetValue("Errors", typeof(SqlErrorCollection)); HResult = HResults.SqlException; } [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] override public void GetObjectData(SerializationInfo si, StreamingContext context) { if (null == si) { throw new ArgumentNullException("si"); } si.AddValue("Errors", _errors, typeof(SqlErrorCollection)); base.GetObjectData(si, context); } [ DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public SqlErrorCollection Errors { get { if (_errors == null) { _errors = new SqlErrorCollection(); } return _errors; } } /*virtual protected*/private bool ShouldSerializeErrors() { // MDAC 65548 return ((null != _errors) && (0 < _errors.Count)); } public byte Class { get { return this.Errors[0].Class;} } public int LineNumber { get { return this.Errors[0].LineNumber;} } public int Number { get { return this.Errors[0].Number;} } public string Procedure { get { return this.Errors[0].Procedure;} } public string Server { get { return this.Errors[0].Server;} } public byte State { get { return this.Errors[0].State;} } override public string Source { get { return this.Errors[0].Source;} } static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion) { Debug.Assert(null != errorCollection, "no errorCollection?"); // concat all messages together MDAC 65533 StringBuilder message = new StringBuilder(); for (int i = 0; i < errorCollection.Count; i++) { if (i > 0) { message.Append(Environment.NewLine); } message.Append(errorCollection[i].Message); } SqlException exception = new SqlException(message.ToString(), errorCollection); exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server"); if (!ADP.IsEmpty(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; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.ComponentModel; using System.Data.Common; using System.Diagnostics; using System.Globalization; using System.Runtime.Serialization; using System.Text; // StringBuilder [Serializable] public sealed class SqlException : System.Data.Common.DbException { private SqlErrorCollection _errors; private SqlException(string message, SqlErrorCollection errorCollection) : base(message) { HResult = HResults.SqlException; _errors = errorCollection; } // runtime will call even if private... private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc) { _errors = (SqlErrorCollection) si.GetValue("Errors", typeof(SqlErrorCollection)); HResult = HResults.SqlException; } [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] override public void GetObjectData(SerializationInfo si, StreamingContext context) { if (null == si) { throw new ArgumentNullException("si"); } si.AddValue("Errors", _errors, typeof(SqlErrorCollection)); base.GetObjectData(si, context); } [ DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public SqlErrorCollection Errors { get { if (_errors == null) { _errors = new SqlErrorCollection(); } return _errors; } } /*virtual protected*/private bool ShouldSerializeErrors() { // MDAC 65548 return ((null != _errors) && (0 < _errors.Count)); } public byte Class { get { return this.Errors[0].Class;} } public int LineNumber { get { return this.Errors[0].LineNumber;} } public int Number { get { return this.Errors[0].Number;} } public string Procedure { get { return this.Errors[0].Procedure;} } public string Server { get { return this.Errors[0].Server;} } public byte State { get { return this.Errors[0].State;} } override public string Source { get { return this.Errors[0].Source;} } static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion) { Debug.Assert(null != errorCollection, "no errorCollection?"); // concat all messages together MDAC 65533 StringBuilder message = new StringBuilder(); for (int i = 0; i < errorCollection.Count; i++) { if (i > 0) { message.Append(Environment.NewLine); } message.Append(errorCollection[i].Message); } SqlException exception = new SqlException(message.ToString(), errorCollection); exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server"); if (!ADP.IsEmpty(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; } } } // 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
- CompoundFileIOPermission.cs
- BehaviorEditorPart.cs
- xdrvalidator.cs
- ValidationPropertyAttribute.cs
- KeyBinding.cs
- unitconverter.cs
- SystemResources.cs
- FragmentQuery.cs
- UniqueIdentifierService.cs
- GPPOINTF.cs
- SinglePageViewer.cs
- DllHostInitializer.cs
- MethodExecutor.cs
- ToolZone.cs
- MarkupProperty.cs
- DocumentViewer.cs
- MenuTracker.cs
- SystemDropShadowChrome.cs
- ConsoleKeyInfo.cs
- MTConfigUtil.cs
- ProfileService.cs
- InputBuffer.cs
- Screen.cs
- DesignerValidatorAdapter.cs
- DataGridViewDataConnection.cs
- SlotInfo.cs
- ParameterReplacerVisitor.cs
- WebControl.cs
- Queue.cs
- Trigger.cs
- SmtpMail.cs
- PatternMatcher.cs
- MappingMetadataHelper.cs
- ClientUtils.cs
- EventTrigger.cs
- ClrPerspective.cs
- TabControlAutomationPeer.cs
- TextDecoration.cs
- ConfigurationStrings.cs
- SessionState.cs
- CacheDict.cs
- FormClosedEvent.cs
- OAVariantLib.cs
- BaseCollection.cs
- Rfc4050KeyFormatter.cs
- DetailsViewUpdatedEventArgs.cs
- ListBindingConverter.cs
- PackageDigitalSignature.cs
- ExpressionNode.cs
- CurrentChangingEventManager.cs
- WorkItem.cs
- DynamicDocumentPaginator.cs
- InvalidOleVariantTypeException.cs
- RoutingExtensionElement.cs
- MultidimensionalArrayItemReference.cs
- WorkflowQueue.cs
- ColorTransformHelper.cs
- RegularExpressionValidator.cs
- XmlAttributeOverrides.cs
- RenderingEventArgs.cs
- UpdateRecord.cs
- TextServicesProperty.cs
- DataGridPageChangedEventArgs.cs
- Pair.cs
- AppSettingsReader.cs
- XmlJsonReader.cs
- TraceSection.cs
- EntityDataSourceStatementEditor.cs
- Table.cs
- StoryFragments.cs
- LineProperties.cs
- ProtocolsInstallComponent.cs
- NameValueSectionHandler.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- EntityDataSourceChangedEventArgs.cs
- Attributes.cs
- VisualTreeUtils.cs
- TypeUnloadedException.cs
- DivideByZeroException.cs
- UrlAuthorizationModule.cs
- TextRenderingModeValidation.cs
- HierarchicalDataSourceControl.cs
- Scanner.cs
- RegexCompilationInfo.cs
- PropertyExpression.cs
- MetadataArtifactLoaderComposite.cs
- MonthCalendar.cs
- SHA1CryptoServiceProvider.cs
- ResourceManagerWrapper.cs
- RegisteredArrayDeclaration.cs
- ToolBarTray.cs
- precedingquery.cs
- TrustManager.cs
- DataGridViewSelectedCellCollection.cs
- ExtractedStateEntry.cs
- FormView.cs
- RepeatButton.cs
- RenderCapability.cs
- SchemaConstraints.cs
- ExtendedTransformFactory.cs