Get the App
SLTechnology News&Howtos  ›  Database  › 

How to call dll file in Sql Server database

Shulou Source: shulou.com Published: 2022-05-31 19:26:14 09月10日 Update

Sql Server database how to call dll files, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need to learn, I hope you can gain something.

1. First create an empty solution, and add a class library, code as follows, 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; } } }

2. Enable CLR functionality

By default, CLR is turned off in SQL Server, so we need to turn it on by executing the following command:

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 functions

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

5. calling function

SELECT dbo.clrHelloWorld ('')

6. execution result

Hello WORLD!

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Tags: Data database function loyalty help file clarity code content writing function command this situation article novice scheme more knowledge program Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Redmi Xiaomi Shulou Information