SqlClient: System.InvalidOperationException: 'Internal connection fatal error.'
I’m looking for some help troubleshooting an issue that I’m having in one of my Development machines.
The following code is throwing a System.InvalidOperationException: ‘Internal connection fatal error.’ when opening the connection.
using System;
using Microsoft.Data.SqlClient;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
using (var connection = new SqlConnection("Server=localhost;Database=Test02;Trusted_Connection=True;"))
{
connection.Open();
Console.WriteLine("Connected successfully.");
Console.ReadKey(true);
}
}
}
}
Here is the stach trace
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, 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)
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()
at ConsoleApp1.Program.Main(String[] args) in Program.cs:line 12
On the same machine, using the legacy library ‘System.Data.SqlClient’, the following code works fine
using System.Data.SqlClient;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
using (var connection = new SqlConnection("Server=localhost;Database=Test02;Trusted_Connection=True;"))
{
connection.Open();
Console.WriteLine("Connected successfully.");
Console.ReadKey(true);
}
}
}
}
I have tried a few things like: Repair .NET 5 Repair SQL Server 2019 Developer Repair VS2019
Does anyone have suggestions that could help to understand the source of the issue?
Thanks
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 21 (9 by maintainers)
.
Exactly: replacing the library and then updating the references across the project.
I’m setting up a new development environment and installing the various tools/frameworks to find out which one makes my project fail running. So far so good …
@pjmolina Thank you for the update. Could you clarify step 1? Do you mean using
Microsoft.Data.SqlClient
instead ofSystem.Data.SqlClient
?Update: fixed on my side doing the following actions:
System.Data.SqlServer
forMicrosoft.Data.SqlServer
Hi @cheenamalhotra it seems we hit the same error here:
Repro conditions:
Scenario A: Client Environment: dotnet 6.0.2 + Dapper 2.0 on Windows 11. Results: It works, connect to DB and makes a simple select query.
Scenario B: Client Environment: dotnet 6.0.2 + Dapper 2.0 on Docker Linux mcr.microsoft.com/dotnet/runtime:6.0.2-alpine3.14-amd64. Results: It fails, unable to connect to DB with the initial exception stack trace.
to discard TLS issues.
Connection string in both scenarios:
Server=10.1.2.3;Database=db;trustServerCertificate=true;Trusted_Connection=false;Encrypt=true;User Id=user;Password=pass;
Expected behavour
Actual behavour
Hi @figueiredorui, what version of Microsoft.Data.SqlClient are you using? Is this a .NET Core or .NET Framework application? You can try enabling event tracing and posting the event log here.