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-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

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!

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