0

我正在尝试完成教程,http://www.codeproject.com/Articles/21149/Invoking-a-WCF-Service-from-a-CLR-Trigger但在尝试部署客户端时遇到问题,输出中出现以下错误:

部署错误 SQL01268:.Net SqlClient 数据提供程序:消息 6503,级别 16,状态 12,第 1 行程序集“system.servicemodel,版本=3.0.0.0,文化=中性,publickeytoken=b77a5c561934e089。” 在 SQL 目录中找不到。

我正在使用 c# 2010、.NET 4.0 和 SQL Server Express 10。

我尝试将项目更改为使用 .NET Framework 3.0 和 3.5,但我仍然收到相同的错误。请问有谁知道如何解决这个问题?

编辑

这可能与我尝试将以下程序集添加到 SQL Server 时遇到的错误有关。

CREATE ASSEMBLY SMDiagnostics 
FROM 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\SMDiagnostics.dll'
WITH permission_set = UNSAFE
GO

CREATE ASSEMBLY [System.Web] 
FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll'
WITH permission_set = UNSAFE
GO

CREATE ASSEMBLY [System.Messaging] 
FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll'
WITH permission_set = UNSAFE
GO

CREATE ASSEMBLY [System.IdentityModel] 
FROM 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.dll'
WITH permission_set = UNSAFE
GO

CREATE ASSEMBLY [System.IdentityModel.Selectors] 
FROM 'C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.Selectors.dll'
WITH permission_set = UNSAFE
GO

-- this will add service modal
CREATE ASSEMBLY [Microsoft.Transactions.Bridge] 
FROM 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication     Foundation\Microsoft.Transactions.Bridge.dll'
WITH permission_set = UNSAFE
GO
4

1 回答 1

2

经过2天的反复试验,我终于让它工作了,就像这样:

(在Windows Server 2008 x64、SQL Server 2008 64 位、使用 Framework 3.0 构建的程序集 DLL、任何 CPU 上)。我建议您坚持使用适用于 SQL 2008 的 .Net 3。

alter database [TTBackup]
set trustworthy on;
go
USE TTBackup
--Register the assemblies referenced by our assembly.
CREATE ASSEMBLY SMdiagnostics AUTHORIZATION dbo FROM 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\SMdiagnostics.dll' WITH permission_set = unsafe
CREATE ASSEMBLY [System.Web] AUTHORIZATION dbo FROM 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Web.dll' WITH permission_set = unsafe
CREATE ASSEMBLY [System.Runtime.Serialization] AUTHORIZATION dbo FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Runtime.Serialization.dll' WITH permission_set = unsafe
CREATE ASSEMBLY [System.IdentityModel.Selectors] FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.Selectors.dll' with permission_set = unsafe 
CREATE ASSEMBLY [System.Messaging] AUTHORIZATION dbo FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll' WITH permission_set = unsafe
CREATE ASSEMBLY [Microsoft.Transactions.Bridge] FROM 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\Microsoft.Transactions.Bridge.dll' with permission_set = unsafe 

--register our assembly
CREATE ASSEMBLY [TTDatabaseIntegration] AUTHORIZATION dbo FROM 'D:\TTDatabaseIntegration.dll' WITH permission_set = unsafe
GO
--Register the UDF from CLR
CREATE FUNCTION [ListImportTemplates]( ) RETURNS TABLE(TemplateID int, TemplateName NVARCHAR(4000))
AS EXTERNAL NAME [TTDatabaseIntegration].[UserDefinedFunctions].[ListImportTemplates]
GO 

--Test my function 
select  * FROM dbo.[ListImportTemplates]()

请注意,大多数引用的 DLL 都是 32 位的,但 System.Web 是 64 位的。(这是它对我有用的唯一方法)。

笔记:

  1. 起初我注册了 64 位程序集,但它引发了运行时异常:System.IO.FileLoadException: Could not load file or assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) See Microsoft Knowledge Base article 949080 for more information.

    我最终将 GAC 中的文件(按大小)与我在 SQL 中注册的文件进行了比较。(GAC 位于 C:\Windows\assembly,但您无法在资源管理器中查看该文件夹,我一直在使用Total Commander。)这就是我发现 GAC 中的版本是 32 位版本的方式。

  2. 您可以使用此查询查看已注册的程序集:SELECT * FROM sys.assemblies

参考资料(逐步解释):

  1. http://nielsb.wordpress.com/sqlclrwcf/
  2. http://hyper-choi.blogspot.ro/2011/07/sql-2008-calling-wcf-service-from.html
于 2014-12-17T10:24:01.437 回答