- 
                Notifications
    You must be signed in to change notification settings 
- Fork 316
Move into Shared for SqlError.cs #1322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 10 commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      7533b74
              
                Merge netfx into netcore for SqlError.cs
              
              
                lcheunglci 1f0ffbd
              
                Move the netcore version of SqlError.cs to shared src and update refe…
              
              
                lcheunglci 567a358
              
                Fix compiler error due to relative path change to the documentation
              
              
                lcheunglci ef55e5d
              
                Resolve merge conflict with the csproj
              
              
                lcheunglci 769d1d1
              
                Add the serializable attribute to the class and change the auto prope…
              
              
                lcheunglci ddd060e
              
                Resolve merge conflict due to the csprojs
              
              
                lcheunglci 292e7af
              
                Resolve merge conflict with csprojs
              
              
                lcheunglci b71180e
              
                Fix compiler error in netfx due to missed merge
              
              
                lcheunglci 4cf5981
              
                Add an ifdef to SqlErrorTest because binary serialization is obsolete…
              
              
                lcheunglci 7fcb4de
              
                Resolve merge conflict in the csproj
              
              
                lcheunglci 22f8821
              
                Update src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTes…
              
              
                DavoudEshtehari File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            72 changes: 0 additions & 72 deletions
          
          72 
        
  src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlError.cs
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            113 changes: 0 additions & 113 deletions
          
          113 
        
  src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlError.cs
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
  
    
      
          
            91 changes: 91 additions & 0 deletions
          
          91 
        
  src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlError.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|  | ||
| using System; | ||
|  | ||
| namespace Microsoft.Data.SqlClient | ||
| { | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/SqlError/*' /> | ||
| [Serializable] | ||
| public sealed class SqlError | ||
| { | ||
| // bug fix - MDAC 48965 - missing source of exception | ||
| private readonly string _source = TdsEnums.SQL_PROVIDER_NAME; | ||
| private readonly int _number; | ||
| private readonly byte _state; | ||
| private readonly byte _errorClass; | ||
| [System.Runtime.Serialization.OptionalField(VersionAdded = 2)] | ||
| private readonly string _server; | ||
| private readonly string _message; | ||
| private readonly string _procedure; | ||
| private readonly int _lineNumber; | ||
| [System.Runtime.Serialization.OptionalField(VersionAdded = 4)] | ||
| private readonly int _win32ErrorCode; | ||
| [System.Runtime.Serialization.OptionalField(VersionAdded = 5)] | ||
| private readonly Exception _exception; | ||
|  | ||
| internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber, uint win32ErrorCode, Exception exception = null) | ||
| : this(infoNumber, errorState, errorClass, server, errorMessage, procedure, lineNumber, exception) | ||
| { | ||
| _server = server; | ||
| _win32ErrorCode = (int)win32ErrorCode; | ||
| } | ||
|  | ||
| internal SqlError(int infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber, Exception exception = null) | ||
| { | ||
| _number = infoNumber; | ||
| _state = errorState; | ||
| _errorClass = errorClass; | ||
| _server = server; | ||
| _message = errorMessage; | ||
| _procedure = procedure; | ||
| _lineNumber = lineNumber; | ||
| _win32ErrorCode = 0; | ||
| _exception = exception; | ||
| if (errorClass != 0) | ||
| { | ||
| SqlClientEventSource.Log.TryTraceEvent("SqlError.ctor | ERR | Info Number {0}, Error State {1}, Error Class {2}, Error Message '{3}', Procedure '{4}', Line Number {5}", infoNumber, (int)errorState, (int)errorClass, errorMessage, procedure ?? "None", (int)lineNumber); | ||
| } | ||
| } | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/ToString/*' /> | ||
| // bug fix - MDAC #49280 - SqlError does not implement ToString(); | ||
| // There is no exception stack included 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 typeof(SqlError).ToString() + ": " + Message; // since this is sealed so we can change GetType to typeof | ||
| } | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Source/*' /> | ||
| // bug fix - MDAC #48965 - missing source of exception | ||
| public string Source => _source; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Number/*' /> | ||
| public int Number => _number; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/State/*' /> | ||
| public byte State => _state; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Class/*' /> | ||
| public byte Class => _errorClass; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Server/*' /> | ||
| public string Server => _server; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Message/*' /> | ||
| public string Message => _message; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/Procedure/*' /> | ||
| public string Procedure => _procedure; | ||
|  | ||
| /// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlError.xml' path='docs/members[@name="SqlError"]/LineNumber/*' /> | ||
| public int LineNumber => _lineNumber; | ||
|  | ||
| internal int Win32ErrorCode => _win32ErrorCode; | ||
|  | ||
| internal Exception Exception => _exception; | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            71 changes: 71 additions & 0 deletions
          
          71 
        
  src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|  | ||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using System.Runtime.Serialization.Formatters.Binary; | ||
| using Xunit; | ||
|  | ||
| namespace Microsoft.Data.SqlClient.Tests | ||
| { | ||
| public class SqlErrorTest | ||
| { | ||
| private const string SQLMSF_FailoverPartnerNotSupported = | ||
| "Connecting to a mirrored SQL Server instance using the MultiSubnetFailover connection option is not supported."; | ||
| private const byte FATAL_ERROR_CLASS = 20; | ||
|  | ||
| #if !NET50_OR_LATER | ||
| [Fact] | ||
| public static void SqlErrorSerializationTest() | ||
| { | ||
| var formatter = new BinaryFormatter(); | ||
| SqlError expected = CreateError(); | ||
| SqlError actual = null; | ||
| using (var stream = new MemoryStream()) | ||
| { | ||
| try | ||
| { | ||
| formatter.Serialize(stream, expected); | ||
| stream.Position = 0; | ||
| actual = (SqlError)formatter.Deserialize(stream); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Assert.False(true, $"Unexpected Exception occurred: {ex.Message}"); | ||
| } | ||
| } | ||
|  | ||
| Assert.Equal(expected.Message, actual.Message); | ||
| Assert.Equal(expected.Number, actual.Number); | ||
| Assert.Equal(expected.State, actual.State); | ||
| Assert.Equal(expected.Class, actual.Class); | ||
| Assert.Equal(expected.Server, actual.Server); | ||
| Assert.Equal(expected.Procedure, actual.Procedure); | ||
| Assert.Equal(expected.LineNumber, actual.LineNumber); | ||
| Assert.Equal(expected.Source, actual.Source); | ||
| } | ||
| #endif | ||
|  | ||
|  | ||
| private static SqlError CreateError() | ||
| { | ||
| string msg = SQLMSF_FailoverPartnerNotSupported; | ||
|  | ||
| Type sqlErrorType = typeof(SqlError); | ||
|  | ||
| // SqlError only has internal constructors, in order to instantiate this, we use reflection | ||
| SqlError sqlError = (SqlError)sqlErrorType.Assembly.CreateInstance( | ||
| sqlErrorType.FullName, | ||
| false, | ||
| BindingFlags.Instance | BindingFlags.NonPublic, | ||
| null, | ||
| new object[] { 0, (byte)0x00, FATAL_ERROR_CLASS, null, msg, "", 0, null }, | ||
|         
                  DavoudEshtehari marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| null, | ||
| null); | ||
|  | ||
| return sqlError; | ||
| } | ||
| } | ||
| } | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.