Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call dll file in Sql Server database

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report