SQL Server calls method instances in Class C # (using. NET assembly ),

Source: Internet
Author: User

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
 

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.