@@ -24,18 +24,19 @@ public sealed record MsSqlConfiguration
2424 /// </summary>
2525 public string ? InstanceName { get ; init ; }
2626 public required string Database { get ; init ; }
27- public required string Username { get ; init ; }
28- public required string Password { get ; init ; }
27+ public string ? Username { get ; init ; }
28+ public string ? Password { get ; init ; }
2929 /// <summary>Optional Windows domain for NTLM auth.</summary>
3030 public string ? Domain { get ; init ; }
31+ public bool IntegratedSecurity { get ; init ; } = false ;
3132 public bool TrustServerCertificate { get ; init ; } = false ;
3233 public bool Encrypt { get ; init ; } = true ;
3334 public int ConnectTimeout { get ; init ; } = 30 ;
3435 public string AppName { get ; init ; } = "CosmoSQLClient" ;
3536
3637 /// <summary>
3738 /// Parse a SQL Server connection string.
38- /// Supports: Server=host,port; Database=...; User Id=...; Password=...; Encrypt=...; TrustServerCertificate=...
39+ /// Supports: Server=host,port; Database=...; User Id=...; Password=...; Encrypt=...; TrustServerCertificate=...; Integrated Security=True
3940 /// </summary>
4041 public static MsSqlConfiguration Parse ( string connectionString )
4142 {
@@ -54,8 +55,12 @@ public static MsSqlConfiguration Parse(string connectionString)
5455 return null ;
5556 }
5657
57- var server = Get ( "Server" , "Data Source" , "DataSource" )
58+ var server = Get ( "Server" , "Data Source" , "DataSource" , "Address" , "Addr" , "Network Address" )
5859 ?? throw new ArgumentException ( "Connection string missing 'Server'." ) ;
60+
61+ // Handle (local) and . aliases
62+ if ( server == "(local)" || server == "." ) server = "localhost" ;
63+
5964 string host = server ;
6065 int port = 1433 ;
6166 string ? instanceName = null ;
@@ -81,18 +86,22 @@ public static MsSqlConfiguration Parse(string connectionString)
8186 bool trustCert = string . Equals ( Get ( "TrustServerCertificate" ) , "true" , StringComparison . OrdinalIgnoreCase )
8287 || string . Equals ( Get ( "TrustServerCertificate" ) , "yes" , StringComparison . OrdinalIgnoreCase ) ;
8388
89+ bool integratedSecurity = string . Equals ( Get ( "Integrated Security" ) , "true" , StringComparison . OrdinalIgnoreCase )
90+ || string . Equals ( Get ( "Integrated Security" ) , "sspi" , StringComparison . OrdinalIgnoreCase )
91+ || string . Equals ( Get ( "Trusted_Connection" ) , "true" , StringComparison . OrdinalIgnoreCase )
92+ || string . Equals ( Get ( "Trusted_Connection" ) , "yes" , StringComparison . OrdinalIgnoreCase ) ;
93+
8494 return new MsSqlConfiguration
8595 {
8696 Host = host ,
8797 Port = port ,
8898 InstanceName = instanceName ,
8999 Database = Get ( "Database" , "Initial Catalog" , "InitialCatalog" )
90100 ?? throw new ArgumentException ( "Connection string missing 'Database'." ) ,
91- Username = Get ( "User Id" , "User ID" , "UserId" , "UID" , "User" )
92- ?? throw new ArgumentException ( "Connection string missing 'User Id'." ) ,
93- Password = Get ( "Password" , "PWD" , "PW" )
94- ?? throw new ArgumentException ( "Connection string missing 'Password'." ) ,
101+ Username = Get ( "User Id" , "User ID" , "UserId" , "UID" , "User" ) ,
102+ Password = Get ( "Password" , "PWD" , "PW" ) ,
95103 Domain = Get ( "Domain" ) ,
104+ IntegratedSecurity = integratedSecurity ,
96105 Encrypt = encrypt ,
97106 TrustServerCertificate = trustCert ,
98107 } ;
@@ -647,12 +656,17 @@ await WritePacketsAsync(TdsPacketType.PreLogin, TdsPreLogin.BuildRequest(wantEnc
647656 }
648657
649658 // ── Login7 ────────────────────────────────────────────────────────────
659+ if ( _config . IntegratedSecurity && string . IsNullOrEmpty ( _config . Username ) )
660+ {
661+ throw SqlException . Auth ( "Integrated Security (SSPI) is not yet supported by this driver. Please provide a User Id and Password." ) ;
662+ }
663+
650664 var loginPayload = TdsLogin7 . Build ( new TdsLogin7 . Options
651665 {
652666 Host = _config . Host ,
653667 Database = _config . Database ,
654- Username = _config . Username ,
655- Password = _config . Password ,
668+ Username = _config . Username ?? string . Empty ,
669+ Password = _config . Password ?? string . Empty ,
656670 Domain = _config . Domain ,
657671 AppName = _config . AppName ,
658672 } ) ;
0 commit comments