SQL SERVER 2005 CLR存儲過程調用WCF,64位操作系統。
前幾天寫過一篇Blog,試驗也成功了,其中有一臺也是64位的操作系統。但是這幾天在另外一臺服務器上部署時就是不行,部署沒有問題,在執行的時候報錯:
消息 6522,級別 16,狀態 1,過程 QueryPseudoCode,第 0 行
在執行用戶定義例程或聚合 'QueryPseudoCode' 期間出現 .NET Framework 錯誤:
System.TypeInitializationException: The type initializer for 'StoreProc.WCF_Query' threw an exception. ---> System.IO.FileLoadException: 未能加載文件或程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一個依賴項。主機存儲區中的程序集與 GAC 中的程序集具有不同的簽名。 (異常來自 HRESULT:0x80131050)
System.IO.FileLoadException:
at StoreProc.WCF_Query..cctor()
System.TypeInitializationException:
at StoreProc.WCF_Query.QueryPseudoCode(Byte queryType, String queryCode, String& queryResult)
。
后來找到另外一個版本的。好像是行了,為什么行了就不知道了。
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE WITH OVERRIDE;
GO
ALTER DATABASE [master] SET Trustworthy ON
CREATE ASSEMBLY
[System.Web] from 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Web.dll'
with permission_set = UNSAFE --Fails if not 64 on 64 bit machines
GO
CREATE ASSEMBLY
SMDiagnostics from 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\SMDiagnostics.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY
[System.Runtime.Serialization] from 'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.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
CREATE ASSEMBLY
[System.Messaging] from 'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Messaging.dll'
with permission_set = UNSAFE
GO
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
------------------------------
use master
CREATE ASSEMBLY
StoreProc from
'D:\StoreProcedure.dll'
with permission_set = UNSAFE
GO
--------------------------------------------------------------
CREATE PROCEDURE [dbo].[QueryPseudoCode]
(
@queryType tinyint,
@queryCode nvarchar(255),
@queryResult nvarchar(255) out
)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [StoreProc].[StoreProc.WCF_Query].[QueryPseudoCode]
GO
--------------------------------------------------------------
CREATE PROCEDURE [dbo].[QueryUserPosition]
(
@numType tinyint,
@num nvarchar(255)
)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [StoreProc].[StoreProc.WCF_Query].[QueryUserPosition]
GO
/*
DROP PROCEDURE QueryPseudoCode
DROP PROCEDURE QueryUserPosition
DROP ASSEMBLY StoreProc
DROP ASSEMBLY [Microsoft.Transactions.Bridge]
DROP ASSEMBLY [System.IdentityModel.Selectors]
DROP ASSEMBLY [System.IdentityModel]
DROP ASSEMBLY [System.Web]
DROP ASSEMBLY [System.Messaging]
DROP ASSEMBLY [System.Runtime.Serialization]
DROP ASSEMBLY [SMDiagnostics]
*/
在提示machine.config異常時,把下面所示的兩行注釋掉就OK了:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\CONFIG\machine.config
<commonBehaviors>
<endpointBehaviors>
<!--<Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior/>-->
</endpointBehaviors>
<serviceBehaviors>
<!--<Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior/>-->
</serviceBehaviors>
</commonBehaviors>

浙公網安備 33010602011771號