Get the App
SLTechnology News&Howtos  ›  Database  › 

How to call dll file in Sql Server database

Shulou Source: shulou.com Published: 2022-05-31 22:08:27 10月01日 Update

How to call the dll file in the Sql Server database? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. First create an empty solution and add a class library with the following code to compile and produce dll

Using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Text; namespace TEST {public class TestTrans {[Microsoft.SqlServer.Server.SqlFunction] public static SqlString GenerateDecryptString (string name) {string decode = string.Empty; decode = string.Format ("HELLO WORLD {0}!", name); / / DecryptString (dataXML.Value); SqlString sqlValue = new SqlString (decode); return sqlValue;}

two。 Enable CLR featur

By default, CLR in SQL Server is off, so we need to execute the following command to open CLR:

Exec sp_configure 'clr enabled',1 reconfigure Go

3. Reference an assembly to a database

CREATE ASSEMBLY testHelloWorld FROM'C:\ TEST.dll'-('C:/TEST.dll'w is misspelled)

4. Create function

CREATE FUNCTION dbo.clrHelloWorld (@ name as nvarchar) RETURNS nvarchar (200) AS EXTERNAL NAME testHelloWorld.[ TEST.TestTrans] .GenerateDecryptString

5. Call function

SELECT dbo.clrHelloWorld ('loyal')

6. Execution result

HELLO WORLD is loyal!

After reading the above, have you mastered how to call the dll file in the Sql Server database? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Data database file content function method more loyal problem helpless for this code writing function reason command this situation skill scheme Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Linux Shulou Technology MySQL