Skip to content

Commit

Permalink
Refactor SqlConnectionString.cs (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcheunglci authored Oct 20, 2021
1 parent 884c67c commit aa95223
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@
</ItemGroup>
<!-- Resources -->
<ItemGroup>
<Compile Include="Resources\$(ResxFileName).Designer.cs">
<Compile Include="Resources\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>$(ResxFileName).resx</DependentUpon>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="..\..\src\Resources\StringsHelper.cs">
<Link>Resources\StringsHelper.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2267,15 +2267,6 @@ internal TdsParser Parser
}
}

internal bool Asynchronous
{
get
{
SqlConnectionString constr = (SqlConnectionString)ConnectionOptions;
return ((null != constr) ? constr.Asynchronous : SqlConnectionString.DEFAULT.Asynchronous);
}
}

//
// INTERNAL METHODS
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ static internal Exception AuthenticationAndIntegratedSecurity()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_AuthenticationAndIntegratedSecurity));
}
static internal Exception IntegratedWithUserIDAndPassword()
static internal Exception IntegratedWithPassword()
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_IntegratedWithUserIDAndPassword));
return ADP.Argument(StringsHelper.GetString(Strings.SQL_IntegratedWithPassword));
}
static internal Exception InteractiveWithPassword()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>"Authentication" kann nicht mit "Integrated Security" verwendet werden.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>"Authentication=Active Directory Integrated" kann nicht mit den Schlüsselwörtern "User ID", "UID", "Password" oder "PWD" für die Verbindungszeichenfolge verwendet werden.</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>"Authentication=Active Directory Integrated" kann nicht mit den Schlüsselwörtern "Password" oder "PWD" für die Verbindungszeichenfolge verwendet werden.</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>"Authentication=Active Directory Interactive" kann nicht mit den Schlüsselwörtern "Password" oder "PWD" für die Verbindungszeichenfolge verwendet werden.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>Der Parameter "{0}" kann keine Ausgaberichtung oder InputOutput aufweisen, wenn EnableOptimizedParameterBinding für den übergeordneten Befehl aktiviert ist.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>No se puede usar 'Authentication' con 'Integrated Security'.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>No se puede usar "Authentication=Active Directory Integrated" con las palabras clave de cadena de conexión "User ID", "UID", "Password" ni "PWD".</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>No se puede usar "Authentication=Active Directory Integrated" con las palabras clave de cadena de conexión "Password" ni "PWD".</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>No se puede usar "Authentication=Active Directory Interactive" con las palabras clave de cadena de conexión "Password" ni "PWD".</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>El parámetro “{0}” no puede tener la Dirección de salida ni InputOutput cuando EnableOptimizedParameterBinding está habilitado en el comando primario.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>Impossible d'utiliser 'Authentication avec 'Integrated Security'.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>Impossible d'utiliser 'Authentication=Active Directory Integrated' avec les mots clés de la chaîne de connexion 'User ID", "UID", "Password" ou "PWD".</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>Impossible d'utiliser 'Authentication=Active Directory Integrated' avec les mots clés de la chaîne de connexion "Password" ou "PWD".</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>Impossible d'utiliser « Authentication=Active Directory Interactive » avec les mots clés de chaîne de connexion « Password » ou « PWD ».</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>Le paramètre « {0} » ne peut pas avoir Direction Output ou InputOutput lorsque EnableOptimizedParameterBinding est activé sur la commande parente.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>Non è possibile usare 'Authentication' con 'Integrated Security'.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>Non è possibile usare 'Authentication=Active Directory Integrated' con le parole chiave della stringa di connessione 'User ID', 'UID', 'Password' o 'PWD'.</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>Non è possibile usare 'Authentication=Active Directory Integrated' con le parole chiave della stringa di connessione 'Password' o 'PWD'.</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>Non è possibile usare 'Authentication=Active Directory Interactive' con le parole chiave della stringa di connessione 'Password' o 'PWD'.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>Il parametro '{0}' non può includere Output o InputOutput come valore di Direction quando nel comando padre è abilitato EnableOptimizedParameterBinding.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>'Authentication' と 'Integrated Security' を一緒に使用することはできません。</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>'Authentication=Active Directory Integrated' と接続文字列キーワード 'User ID'、'UID'、'Password'、'PWD' を一緒に使用することはできません。</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>'Authentication=Active Directory Integrated' と接続文字列キーワード 'Password'、'PWD' を一緒に使用することはできません。</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>'Authentication=Active Directory Interactive' と接続文字列キーワード 'Password'、'PWD' を一緒に使用することはできません。</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>親コマンドで EnableOptimizedParameterBinding が有効になっている場合、パラメーター '{0}' に Direction 出力または InputOutput は指定できません。</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>'Authentication'을 'Integrated Security'와 함께 사용할 수 없습니다.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>'Authentication=Active Directory Integrated'를 'User ID', 'UID', 'Password' 또는 'PWD' 연결 문자열 키워드와 함께 사용할 수 없습니다.</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>'Authentication=Active Directory Integrated'를 'Password' 또는 'PWD' 연결 문자열 키워드와 함께 사용할 수 없습니다.</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>'Authentication=Active Directory Interactive'를 'Password' 또는 'PWD' 연결 문자열 키워드와 함께 사용할 수 없습니다.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>부모 명령에서 EnableOptimizedParameterBinding을 사용하는 경우 매개 변수 '{0}'에는 Direction Output 또는 InputOutput을 사용할 수 없습니다.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>Não é possível usar "Authentication" com "Integrated Security".</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>Não é possível usar 'Authentication=Active Directory Integrated' com as palavras-chave de cadeia de conexão 'User ID', 'UID', 'Password' ou 'PWD'.</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>Não é possível usar 'Authentication=Active Directory Integrated' com as palavras-chave de cadeia de conexão 'Password' ou 'PWD'.</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>Não é possível usar 'Authentication=Active Directory Interactive' com as palavras-chave de cadeia de conexão 'Password' ou 'PWD'.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>O parâmetro '{0}' não pode ter a saída de direção ou InputOutput quando EnableOptimizedParameterBinding está habilitado no comando pai.</value>
</data>
</root>
</root>
6 changes: 3 additions & 3 deletions src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>Cannot use 'Authentication' with 'Integrated Security'.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>Cannot use 'Authentication=Active Directory Integrated' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords.</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>Cannot use 'Authentication=Active Directory Integrated' with 'Password' or 'PWD' connection string keywords.</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>Cannot use 'Authentication=Active Directory Interactive' with 'Password' or 'PWD' connection string keywords.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>Parameter '{0}' cannot have Direction Output or InputOutput when EnableOptimizedParameterBinding is enabled on the parent command.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>Нельзя использовать 'Authentication' с 'Integrated Security'.</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>Невозможно использовать "Authentication=Active Directory Integrated" с ключевыми словами строки подключения "User ID", "UID", "Password" или "PWD".</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>Невозможно использовать "Authentication=Active Directory Integrated" с ключевыми словами строки подключения "Password" или "PWD".</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>Невозможно использовать "Authentication=Active Directory Interactive" с ключевыми словами "Password" или "PWD" в строке подключения.</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>У параметра "{0}" не может быть направления вывода или InputOutput, если EnableOptimizedParameterBinding включен в родительской команде.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>无法对“Integrated Security”使用“Authentication”。</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>无法对“User ID”、“UID”、“Password”或“PWD”连接字符串关键字使用“Authentication=Active Directory Integrated”。</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>无法对“Password”或“PWD”连接字符串关键字使用“Authentication=Active Directory Integrated”。</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>无法对 "Password" 或 "PWD" 连接字符串关键字使用 "Authentication=Active Directory Interactive"。</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>当在父命令上启用 EnableOptimizedParameterBinding 时,参数“{0}”不能具有 Direction Output 或 InputOutput。</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2493,8 +2493,8 @@
<data name="SQL_AuthenticationAndIntegratedSecurity" xml:space="preserve">
<value>無法搭配 'Integrated Security' 使用 'Authentication'。</value>
</data>
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
<value>無法搭配 'User ID'、'UID'、'Password' 或 'PWD' 等連接字串關鍵字使用 'Authentication=Active Directory Integrated'。</value>
<data name="SQL_IntegratedWithPassword" xml:space="preserve">
<value>無法搭配 'Password' 或 'PWD' 等連接字串關鍵字使用 'Authentication=Active Directory Integrated'。</value>
</data>
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
<value>使用 'Authentication=Active Directory Interactive' 時,無法搭配 'Password' 或 'PWD' 連接字串關鍵字一起使用。</value>
Expand Down Expand Up @@ -4617,4 +4617,4 @@
<data name="SQL_ParameterDirectionInvalidForOptimizedBinding" xml:space="preserve">
<value>在父命令上啟用 EnableOptimizedParameterBinding 時,參數 '{0}' 不能具有方向輸出或 InputOutput。</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ internal static class DbConnectionStringDefaults
internal const bool ContextConnection = false;
internal static readonly bool TransparentNetworkIPResolution = !LocalAppContextSwitches.DisableTNIRByDefault;
internal const string NetworkLibrary = "";
internal const bool Asynchronous = false;
#if ADONET_CERT_AUTH
internal const string Certificate = "";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ internal static class DEFAULT
internal static readonly SqlConnectionIPAddressPreference IpAddressPreference = DbConnectionStringDefaults.IPAddressPreference;
#if NETFRAMEWORK
internal static readonly bool TransparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
internal const bool Asynchronous = DbConnectionStringDefaults.Asynchronous;
internal const bool Connection_Reset = DbConnectionStringDefaults.ConnectionReset;
internal const bool Context_Connection = DbConnectionStringDefaults.ContextConnection;
internal const string Network_Library = DbConnectionStringDefaults.NetworkLibrary;
Expand Down Expand Up @@ -572,17 +571,10 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
throw SQL.AuthenticationAndIntegratedSecurity();
}

#if NETFRAMEWORK
if (Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated && (_hasUserIdKeyword || _hasPasswordKeyword))
{
throw SQL.IntegratedWithUserIDAndPassword();
}
#else
if (Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated && _hasPasswordKeyword)
{
throw SQL.IntegratedWithPassword();
}
#endif

if (Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive && _hasPasswordKeyword)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ public void GetSchema_Connection_Closed()
Assert.NotNull(ex.Message);
}

[Theory]
[InlineData("Authentication = ActiveDirectoryIntegrated;Password = ''")]
[InlineData("Authentication = ActiveDirectoryIntegrated;PWD = ''")]
[InlineData("Authentication = ActiveDirectoryIntegrated;User Id='';PWD = ''")]
[InlineData("Authentication = ActiveDirectoryIntegrated;User Id='';Password = ''")]
[InlineData("Authentication = ActiveDirectoryIntegrated;UID='';PWD = ''")]
[InlineData("Authentication = ActiveDirectoryIntegrated;UID='';Password = ''")]
public void ConnectionString_ActiveDirectoryIntegrated_Password(string connectionString)
{
SqlConnection cn = new SqlConnection();

ArgumentException ex = Assert.Throws<ArgumentException>(() => cn.ConnectionString = connectionString);
// Invalid value for key 'user instance'
Assert.Null(ex.InnerException);
Assert.NotNull(ex.Message);
Assert.True(ex.Message.IndexOf("'pwd'", StringComparison.OrdinalIgnoreCase) != -1);
Assert.Null(ex.ParamName);
}

[Theory]
[InlineData(@"AttachDbFileName=C:\test\attach.mdf", @"AttachDbFileName=C:\test\attach.mdf")]
[InlineData(@"AttachDbFileName=C:\test\attach.mdf;", @"AttachDbFileName=C:\test\attach.mdf;")]
Expand Down

0 comments on commit aa95223

Please sign in to comment.