Add Assembly from SQL Server Database Project with Other DLL dependencies - sql-server

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.

Related

Cannot publish DACPAC to local SQL Server container, external users not valid logins

We have an Azure SQL Server database. I'm trying to implement a better CI/CD workflow by using SQL database projects. I want to create a DACPAC from the production database and apply it to a local container for development.
I've installed the extension Database Projects in Azure Data Studio and I have Docker running.
In the Database Projects extension, create project from database. I select our existing production database in Azure. Folder structure = Schema/Object Type, SDK-Style project enabled.
Build the project. I get 0 errors and 357 warnings. Mostly warnings about that object references differ in case SQL71558 or unresolved references SQL71502.
Publish project to new SQL Server local development container. The docker container is published, but the "Deploy dacpac"-stage fails with error:
Deploy dacpac: Could not deploy package.
Warning SQL0: A project which specifies SQL Server 2019 as the target platform may experience compatibility issues with SQL Server 2017.
Warning SQL0: The source contains users that rely on an external authentication provider that is not supported by the target. These users will be treated as users without logins.
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 15007, Level 16, State 1, Line 1 'DATAFACTORY' is not a valid login or you do not have permission.
Error SQL72045: Script execution error. The executed script:
CREATE USER [DATAFACTORY] FOR LOGIN [DATAFACTORY];
Go back and change the target platform to Azure SQL Server and build the project again.
Publish the project with the base image set to Azure SQL Database emulator full. Same error:
Deploy dacpac: Could not deploy package.
Warning SQL0: The source contains users that rely on an external authentication provider that is not supported by the target. These users will be treated as users without logins.
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 15007, Level 16, State 1, Line 1 'DATAFACTORY' is not a valid login or you do not have permission.
Error SQL72045: Script execution error. The executed script:
CREATE USER [DATAFACTORY] FOR LOGIN [DATAFACTORY];
I've also tried adding the master as a database reference. I've tried this in Azure Data Studio, Visual Studio Code and Visual Studio 2019.
According to an answer from the Azure Data Studio team this could be because of a bug that will be fixed in the next release.
To exclude the User Object Type from the publish action to the Docker container, I had to create a DAC Publish Profile in Visual Studio 2019 and then use it when publishing to my local emulator. That particular error disappeared but I've not verified that it's actually resolved since the next error came up.
If anyone else gets a similar problem you can try using this database.publish.xml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>database</TargetDatabaseName>
<DeployScriptFileName>database.sql</DeployScriptFileName>
<ProfileVersionNumber>1</ProfileVersionNumber>
<CreateNewDatabase>True</CreateNewDatabase>
<ExcludeObjectTypes>Users</ExcludeObjectTypes>
</PropertyGroup>
</Project>

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.

CLR Runtime error framework 3.5 - System.Security.HostProtectionException

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.

Error during SSIS package deploy - Failed to create AppDomain "SSISDB.dbo[runtime]

I'm trying to deploy package on SQL Server and during execution I'm getting following error.
On server already exists packages so it shouldn;t be problem with SQL Server Configuration itself.
Any ideas?
Failed to create AppDomain "SSISDB.dbo[runtime].18".
Could not load file or assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Not enough storage is available to process this command. (Exception from HRESULT: 0x80070008) (.Net SqlClient Data Provider)
Note from your post "Not enough storage is available to process this command" you don't have enough storage available. Another thing you have to set overwrite property for your ssis project.

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