search
HomeDatabaseMysql TutorialSql2008中添加程序集.

Sql2008中添加程序集.

Jun 07, 2016 pm 03:13 PM
sql2008EstablishdatabaseAdd toprogramproject

C# 建立数据库 CRL 项目 .Net 3.5 public partial class MyClr{ [Microsoft.SqlServer.Server.SqlFunction] public static SqlBoolean CLRFBitContains(string MyBigIntValue, int Row) { // 在此处放置代码 return (new MyBigInt(MyBigIntValue) MyBigInt.C

C# 建立数据库 CRL 项目  .Net 3.5

public partial class MyClr
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlBoolean CLRFBitContains(string MyBigIntValue, int Row)
    {
        // 在此处放置代码
        return (new MyBigInt(MyBigIntValue) & MyBigInt.CreateByBitPositon(Convert.ToUInt32(Row))) == MyBigInt.Zero;
    }
}

  数据库初始化:

exec sp_configure 'show advanced options', '1';
go
reconfigure;
go
exec sp_configure 'clr enabled', '1'
go
reconfigure;
exec sp_configure 'show advanced options', '1'; 

go
  ALTER DATABASE DB_Name set TRUSTWORTHY on;
go

  数据库添加程序集:

create assembly MyClr
from 'R:\MyApp\MyClr\MyClr\bin\Debug\MyClr.dll'
WITH permission_set = Safe;

  数据库添加函数映射

create function ClrFBitContains
( @val as nvarchar(4000) , @RowIndex as  int )
returns bit
as 
  external  name MyClr.MyClr.CLRFBitContains  ;

  

TestSql:

 select dbo.ClrFBitContains('F0F',11)

======================================================

原文很丑: http://www.ej38.com/showinfo/sqlserver-140374.html

在sqlserver中如果要使用一个程序集一般有如下注意事项 

一:打开sqlserver 的CLR支持

 --在Sql Server中执行这段代码可以开启CLR 

exec sp_configure 'show advanced options''1';
go
reconfigure;
go
exec sp_configure 'clr enabled''1'
go
reconfigure;
exec sp_configure 'show advanced options''1'

go

 

二:是否需要访问外部资源,如果需要访问外部资源还需要执行下面的

  --打开数据库的TRUSTWORTHY 属性
  ALTER DATABASE DB_Name set TRUSTWORTHY on;

 

**在sqlserver中如果要使用一个程序集一般有两种方法 

 方法一:通过T-SQL手动将该程序集放入到SQL Server 其步骤如下

一:创建将要使用的程序集.dll

   程序上没什么稀奇的,跟普通的ado.net的程序差不多主要就是方法上加了一个属性  ()

二:部署程序集到sqlserver

        a打开sqlserver中clr中相关的支持(方法如上)

        b添加程序集到sqlserver

                              

                              CREATE  assembly SqlServerProject1
                              authorization dbo
                              from 'E:\test\dotnet\SqlServerProject1\SqlServerProject1\bin\SqlServerProject1.dll'
                              with permission_set=external_access
                              go
                

  c添加存储过程

--添加存储过程
CREATE PROCEDURE [dbo].[存储过程名称]
    @from [nvarchar](50), -- 参数列表
    @to [nvarchar](50)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [程序集的名称].[StoredProcedures].[存储过程名称]

 

  d执行存储过程

              exec CLRSPTest @sql='select * from t2',@path='e:\a\11.txt'

 

  方法二:通过Visual Studio 2005创建供并部署SQL Server 2005用的Assembly

                      一:打开Visual Studio 2005新建项目类型为数据库的sqlserver项目

                      二:创建所需要的存储过程,函数等

                      三:编译该项目

                      四:部署该项目(此时我们打开sqlserver相应的数据库可以看到存储过程目录及程序集等目录下有相应创建的对象了)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

The Ultimate Guide to Adding Users in MySQLThe Ultimate Guide to Adding Users in MySQLMay 07, 2025 pm 03:29 PM

ToaddauserinMySQL,usetheCREATEUSERstatement.1)UseCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';tocreateauser.2)Enforcestrongpasswordpolicieswithvalidate_passwordpluginsettings.3)GrantspecificprivilegesusingGRANTstatement.4)Forremoteaccess,use

What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor