SQL Server calls method instances in Class C # (using. NET assembly ),
The requirement is as follows. when operating data in the. net program, some field data is encrypted, which is shared by many systems. One of the delphi programs also needs to be used and the data needs to be decrypted. the encryption method in. net is special. It takes a lot of time to decrypt data in the delphi Program. Therefore, sqlserver has to call the assembly method to solve the problem.
The following is an example of sharing.
Create a dll and class. The Code is as follows:
Copy codeThe Code is as follows:
Namespace MyDll
{
Public partial class MyClass
{
[SqlMethod]
Public static SqlString UrlDecode (string value)
{
Return new SqlString (HttpUtility. UrlDecode (value ));
}
}
}
Put it on the database server.
Then run the following T-SQL code:
Copy codeThe Code is as follows:
EXEC sp_configure 'show advanced options', '1 ';
GO
RECONFIGURE;
GO
EXEC sp_configure 'clr enabled', '1'
RECONFIGURE;
GO
Alter database DBName SET TRUSTWORTHY ON
GO
CREATE ASSEMBLY
[System. Web] FROM
'C: \ WINDOWS \ Microsoft. NET \ Framework64 \ v2.0.50727 \ System. Web. dll'
WITH permission_set = UNSAFE
GO
Create assembly SQL _CLR_Url
FROM 'C: \ MyDLL. dll'
WITH PERMISSION_SET = UNSAFE
GO
Create function SqlUrlDecode (@ urlstr NVARCHAR (4000 ))
Returns nvarchar (4000)
AS
External name SQL _CLR_Url. [SqlClr. MyClass]. UrlDecode
GO
Then you can call this function in the T-SQL.
Copy codeThe Code is as follows:
Select dbo. SqlUrlDecode (Name) from Table
How can I use a database (SQL server) in c/c ++ programming )?
To operate SQL server, you need to use the ADO driver, which has many packaging classes using MFC. Writing code directly on the console may be a little complicated.
Refer
Wenku.baidu.com/...d.html
In SQL Server2005, the following statements that call the stored procedure are incorrect:
D.
Out... what