You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When my database name has a [space] in it, the SqlConnectionStringBuilder wraps the InitialCatalog in double quotes. When the resulting ConnectionString() value is used by a SqlConnection a connection exception occurs.
The connection opens fine with:
Data Source=(local);Initial Catalog=Development - Core;Integrated Security=True;Trust Server Certificate=True;Application Name=MyApp;Multi Subnet Failover=True
The connection fails with the SqlConnectionStringBuilder generated string:
Data Source=(local);Initial Catalog="Development - Core";Integrated Security=True;Trust Server Certificate=True;Application Name=MyApp;Multi Subnet Failover=True
Exception message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The remote computer refused the network connection.)
Stack trace: at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, TimeoutTimer timeout, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, Func`3 accessTokenCallback)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
Expected behavior
The double quotes should not be added when they are not required and should certainly not 'break' the connection string!
Further technical details
Microsoft.Data.SqlClient version: 6.0.1
.NET target: .NET 9
SQL Server version: SQL Server 2022
Operating system: Windows 11
Additional context
I appreciate that this may be an issue in the SQLConnection itself, if the double-quotes shouldn't affect the connection (even though they aren't required). If it were this would still be an issue in this package.
The text was updated successfully, but these errors were encountered:
I've actually found that if I enable TCP/IP on the machine that the double quotes don't cause a problem. Suggesting to me that when the Initial Catalog includes double quotes, the Shared Memory protocol isn't used.
So this feels like a combination of issues:
double quotes shouldn't be added when they aren't needed by the Connection String Builder
the Shared Memory protocol should be used when the Initial Catalog has double quotes in
When my database name has a [space] in it, the SqlConnectionStringBuilder wraps the InitialCatalog in double quotes. When the resulting ConnectionString() value is used by a SqlConnection a connection exception occurs.
The connection opens fine with:
Data Source=(local);Initial Catalog=Development - Core;Integrated Security=True;Trust Server Certificate=True;Application Name=MyApp;Multi Subnet Failover=True
The connection fails with the SqlConnectionStringBuilder generated string:
Data Source=(local);Initial Catalog="Development - Core";Integrated Security=True;Trust Server Certificate=True;Application Name=MyApp;Multi Subnet Failover=True
Expected behavior
The double quotes should not be added when they are not required and should certainly not 'break' the connection string!
Further technical details
Microsoft.Data.SqlClient version: 6.0.1
.NET target: .NET 9
SQL Server version: SQL Server 2022
Operating system: Windows 11
Additional context
I appreciate that this may be an issue in the SQLConnection itself, if the double-quotes shouldn't affect the connection (even though they aren't required). If it were this would still be an issue in this package.
The text was updated successfully, but these errors were encountered: