SQL calls C # DLL (second DLL, strong name key)

Source: Internet
Author: User

Reference: Microsoft Official website https://msdn.microsoft.com/zh-cn/library/ms345106 (es-es). aspx

1. New Project Sqldlltestusingnew

Class1 Class Code:

using system.web; namespace sqldlltestusingnew{    publicclass  Class1    {         public  Staticstring getstr (string  par1)        {            return"  watermark New";        }}    }

2. The Class Library project is signed, and the "project" is compiled after signing:

3. enable CLR features : By default, the CLR in SQL Server is turned off,

exec ' CLR enabled ',1  reconfigure  go

4.

Registering DLLs:

In order to invoke the method we wrote, we need to register the DLL we just compiled in SQL Server. Before you do this, you should be aware that you want to configure permissions on this project if you want to access resources other than the server. If not configured, an error similar to the following will appear in subsequent operations. What I found about the authorization configuration: Connect.

Create a login and key, if the assembly has changed, to delete the key and re-create the login name:

 Use Master;--This must be the Master library GO   CREATE KEY  from FILE = ' D:\SQLDllTestUsingNew.dll '  CREATE  from KEY Sqlclrsynckey    GRANT  to Sqlclrsynclogin;

After you create the assembly, the DLL changes to remove the re-created code as follows:

DROP LOGIN Sqlclrsynclogin DROP KEY Sqlclrsynckey

5, create the assembly, after the DLL changes to remove the re-create:

 Use TestDB Go Create  from 'D:\SQLDllTestUsingNew.dll'with= external_access;

6. Create a function to call this DLL

CREATE FUNCTION Dbo.fun_sync (      @strSqlnvarchar(max))RETURNS  nvarchar(max)  as[mysync].  [sqldlltestusingnew.class1]. [getstr]

7. Call the created function.

Select Dbo.fun_sync (' DSDFG ')

Results: DSDFG Watermark New

SQL calls C # DLL (second DLL, strong name key)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.