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)