Describe the bug
I have a windows service which works fine for maybe a week and then it suddenly gets exception DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll' in SqlConnection.Open
Retrying the operation gives same exception.
Restarting the service fixes the problem for another week or so.
Have seen this in 2 different applications running on different servers.
One application is busy during working hours, the other only accesses the database maybe 10 times a day.
- TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.
TypeName = "Microsoft.Data.SqlClient.TdsParser"
- TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.
TypeName = "Microsoft.Data.SqlClient.SNILoadHandle"
- DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
TypeName = ""
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
at Microsoft.Data.SqlClient.SNILoadHandle..ctor()
at Microsoft.Data.SqlClient.SNILoadHandle..cctor()
at Microsoft.Data.SqlClient.TdsParserStateObjectFactory.get_EncryptionOptions()
at Microsoft.Data.SqlClient.TdsParser..cctor()
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()
To reproduce
Expected behavior
Expect no exception.
Further technical details
Microsoft.Data.SqlClient version: 5.2.2
.NET target: net 8.0
SQL Server version: SQL Server 2019
Operating system: Windows Server 2019
Edit: Sorry, forgot an important detail!
Both applications use "Produce single file" and has <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
Could it be that the self-extract can only load a native assembly once?
Additional context
Looked at the troubleshooting guide but it just says "Microsoft.Data.SqlClient doesn't manage loading/unloading of this library in .NET Core.".
What manages the loading/unloading and why does it get unloaded while the application is running?
Describe the bug
I have a windows service which works fine for maybe a week and then it suddenly gets exception
DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll'in SqlConnection.OpenRetrying the operation gives same exception.
Restarting the service fixes the problem for another week or so.
Have seen this in 2 different applications running on different servers.
One application is busy during working hours, the other only accesses the database maybe 10 times a day.
To reproduce
Expected behavior
Expect no exception.
Further technical details
Microsoft.Data.SqlClient version: 5.2.2
.NET target: net 8.0
SQL Server version: SQL Server 2019
Operating system: Windows Server 2019
Edit: Sorry, forgot an important detail!
Both applications use "Produce single file" and has
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>Could it be that the self-extract can only load a native assembly once?
Additional context
Looked at the troubleshooting guide but it just says "Microsoft.Data.SqlClient doesn't manage loading/unloading of this library in .NET Core.".
What manages the loading/unloading and why does it get unloaded while the application is running?