Unable to load DLL 'sni.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED))

1

I'm trying to use Entity Framework Core 3.1.7 (code first) with SQL Server Express.

add-migration works well but when I try to migrate to the database I

System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED))
   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()
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParserStateObjectFactory.get_EncryptionOptions()
   at Microsoft.Data.SqlClient.TdsParser..cctor()
   --- End of inner exception stack trace ---

If I look for the file, it is there under ..\bin\Debug\netcoreapp3.1\runtimes\win-x64\native\

btw Did try installing Microsoft.Data.SqlClient Nuget package but get the same error different

entity-framework-core
asked on Stack Overflow Aug 18, 2020 by Adrian Sanchez

1 Answer

2

After a day and a half, I figure it out. It was the connection string (I'm using SQL Server Express) I changed 'localhost' for the computer's name and it worked.

answered on Stack Overflow Aug 18, 2020 by Adrian Sanchez

User contributions licensed under CC BY-SA 3.0