SQL运行CLR报异常

最近的工作是导数据库,把原有库里的内容导入到新的数据库中。

遇到这么一个问题。新数据库有个表有trigger,trigger又调用一个function.function里面是运行CLR加密。(SHIT)

正常插入数据都没有问题,但是我写SQL导入数据,抛异常

An error occurred in the Microsoft .NET Framework while trying to load assembly id 655..

找了一下,微软官方有个结局方案。

To resolve the trust issue, open SQL Management and execute the following SQL statement against every restored/attached database:

You may have to run the statements below against your application database, forms, templates and object databases.

ALTER DATABASE dbname SET TRUSTWORTHY ON


You may have to run this script below against your application database, forms, templates and object databases.

--Run this script against the database that was restored.
--script start
DECLARE @master_owner sysname

SELECT @master_owner = sl.name

from master..syslogins sl

inner join sys.databases sd on

sd.owner_sid = sl.sid

where sd.name = 'master'

DECLARE @my_owner sysname

SELECT @my_owner = sl.name

from master..syslogins sl

inner join sys.databases sd on

sd.owner_sid = sl.sid

where sd.name = DB_NAME()

IF ISNULL(@my_owner, N'') <> @master_owner

BEGIN

DECLARE @SQL1 nvarchar(4000)

SET @SQL1 = N'ALTER AUTHORIZATION ON DATABASE::' + DB_NAME()

+ ' TO ' + @master_owner

EXECUTE (@SQL1)

END

GO

DECLARE @SQL nvarchar(4000)

SET @SQL = N'ALTER DATABASE ' + DB_NAME() + N' SET TRUSTWORTHY ON'

EXECUTE (@SQL)

GO

--script end

Note:
To set this option, you must be a member of the sysadmin fixed server role, which the sa user is by default.
Make sure to log into SQL Mgt Studio, with SQL authentication and the 'sa' user

posted @ 2011-02-25 11:37  桔红糕  阅读(298)  评论(0编辑  收藏  举报