CLR Runtime error framework 3.5 - System.Security.HostProtectionException - sql-server

I´ve created a CLR Runtime dll following the steps of this post - https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b732a134-33ba-4880-838d-33fb93887d12/decript-data-on-field-level-that-was-encrypted-on-an-oracle-system?forum=transactsql
It was created for SQL Server 2012 and it works perfectly.
The problem is that the client database is SQL Server 2008 and a new project had to be created for due to the framework 3.5.
So a new dll was created and when I call it on SQL Server 2008 I´m having the following error message.
Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "DecryptDataDecimal":
System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.
The protected resources (only available with full trust) were: All
The demanded resources were: MayLeakOnAbort
System.Security.HostProtectionException:
at UserDefinedFunctions.Decrypt_AES(Byte[] cypherText, Byte[] Key, Byte[] IV)
at UserDefinedFunctions.DecryptDataDecimal(String EncryptedData)
Thanks in advance.

Related

Add Assembly from SQL Server Database Project with Other DLL dependencies

I am currently having an issue deploying some assemblies to using Visual Studio 2022. One Assembly is dependent of MySQl.data.dll and I get the error message below
Error: SQL72014: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'mysql.data, version=8.0.31.0, culture=neutral, publickeytoken=xxxxx' was not found in the SQL catalog.
When I tried to manually load MySQL.data.dll I get the error message below
CREATE ASSEMBLY for assembly 'MySQl.data' failed because assembly 'MySQl.data' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message.
Any help will be much appreciated.

Successful SQL login failing when publishing database through Visual Studio

I'm trying to publish my database through Visual Studio to a SQL Server running on a colleague's virtual machine (testing environment).
When testing the connection in Visual Studio, the test succeeds
When actually publishing the project to the server and database seen in the picture, publishing fails and I get this error message:
(47,1): SQL72014: .Net SqlClient Data Provider: Msg 18456, Level 14, State 1, Line 1 Fehler bei der Anmeldung für den Benutzer "sa"."
Which translates to: "Login error for the user "sa""
I'm not sure what to do here, as I can use the exact same credentials when logging into the SQL Server through SSMS without any problems. I am using Visual Studio Professional 2019 v16.6.2 if it helps.
Rookie mistake, i guess. In one of the scripts which are executed when publishing, i need to get data from another server where the login credentials for the "sa"-user are different. That's why i get the error message.

SQL Server Reporting Server data source connection fails when using Always Encrypted feature

We're using "Always Encrypted" feature in SQL Server to encrypt a few columns. Encryption works fine on MVC/SQL side. Only issue we have is with the SQL reporting server. Able to run the reports when the data source connection string is
Server=mssqlserver;Database=MYDATABASE;Integrated Security=true
But when I try to run the reports from the MVC application, it automatically adds the Column Encryption Setting=enabled to the connection string
Server=mssqlserver;Database=MYDATABASE;Integrated Security=true;Column Encryption Setting=enabled
When I enter the credentials and click 'Test Connection', it throws an error
Keyword not supported: 'column encryption setting'
Because of the above error, it cannot make a connection to the data source 'MYDATABASE'. Tried giving permission to the reporting server service account and the account used
to connect to the database to access the keys to encrypt/decrypt but no luck. How can I fix this issue? We're using SQL Server 2017.
This error is to do with the version of SSRS you are running. Under the covers, SSRS uses .net framework to connect to data sources. This version does not understand the keyword provided.
From the screenshot it looks like SSRS 2008R2, this targets .net 3.5. Always Encrypted (AE) is not supported until 4.6 (SSRS 2019). As far as I am aware you cannot change SSRS's target framework.
To get around this issue I suggest either:
1. Install an alternate data source provider that supports AE (i.e. Microsoft ODBC Driver for SQL Server 17.4 or above), then update the data source's connection string to use this
2. Upgrade SSRS to 2019
Hope this helps

Getting error (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY) when migrating from MS Access 2013 to SQL Server 2014

OK.... I've checked and rechecked Google, StackFault, Experts-Exchange, etc... for a resolution on this error and they all say to register the DAO360.DLL and add its path to the environment settings. I've done that several times and I still get the following error:
Access Object Collector error: Database
Unable to cast COM object of type 'Microsoft.Office.Interop.Access.Dao.DBEngineClass' to interface type 'Microsoft.Office.Interop.Access.Dao._DBEngine'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00000021-0000-0010-8000-00AA006D2EA4}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
An error occurred while loading database content.
I'm not using compression and this is a clean install of Windows 7 Enterprise x64, Office 2013 Pro Plus x64 and SQL Server 2014 Enterprise.
I am migrating from an 2013 .accdb to SQL 2014. I have tried previous versions as well. And I am using the migration wizard from SSMA 6.0.
What am I missing, overlooking, needing to do, etc...?

asp.net 4 mvc 2 error

when I run the app on server I get:
Could not load file or assembly 'Microsoft.SqlServer.Replication.DLL' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.SqlServer.Replication.DLL' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
Some points:
On machines with sql server 2005 installed (from which that dll is copied) the app works. But the server does not have it, so I need to get it to work without sql server.
The file is in wwwroot/bin folder: Microsoft.SqlServer.Replication.dll
Do I need to include the file in References folder in VS? Set it to CopyLocal?
Any advice or solutions would be greatly appreciated
--MB
The Microsoft.SqlServer.Replication.DLL is part of the Replication Management Objects which in turn are part of the SMO pack. The only supported redistribution path for SMO is to use the installer that comes with the SQL Server feature pack download, see Distributing an Application That Uses SQL Server Management Objects. You must install the SMO redistributable packet on the server.

Resources