【问题标题】:Deploy Failed : CLR Trigger部署失败:CLR 触发器
【发布时间】:2012-02-12 20:31:24
【问题描述】:

我正在尝试部署基于 .Net 4.0 构建的 CLR 触发器,但将目标框架更改为 3.0,但我收到以下错误消息。

------ 部署开始:项目:ServiceClient,配置:调试任何 CPU ------ 构建于 2012 年 1 月 18 日下午 2:16:24 开始。 SqlClr部署: 开始将程序集 ServiceClient.dll 部署到服务器 WS037298:custDB 如果部署为与 SQL Server 目标实例不兼容的 .NET Framework 版本构建的 SQL CLR 项目,则可能会出现以下错误:“部署错误 SQL01268:为程序集创建程序集失败,因为程序集验证失败”。要解决此问题,请打开项目的属性,然后更改 .NET Framework 版本。 生成的部署脚本: D:\Visual Studio 2010\Projects\ServiceClient\ServiceClient\bin\Debug\ServiceClient.sql

正在创建 [ServiceClient]... D:\Visual Studio 2010\Projects\ServiceClient\ServiceClient\bin\Debug\ServiceClient.sql(39-39): 部署错误 SQL01268: .Net SqlClient 数据提供者: Msg 6503, Level 16, State 12, Line 1 Assembly 'system .servicemodel,版本=3.0.0.0,文化=中性,publickeytoken=b77a5c561934e089。在 SQL 目录中找不到。 执行批处理时出错。

构建失败。

经过时间 00:00:24.64 ========== 构建:1 个成功或最新,0 个失败,0 个跳过 ========== ========== 部署:0 成功,1 失败,0 跳过 ==========

public partial class Triggers
{
    //Create an endpoint addresss for our serivce
    public static EndpointAddress endpoint =
      new EndpointAddress(new Uri("http://localhost:8000/services/myservice"));
    //Create a binding method for our service
    public static WSHttpBinding httpBinding = new WSHttpBinding();
    //Create an instance of the service proxy
    public static ServiceClient.ServiceReference1.ServiceContractClient myclient = new ServiceClient.ServiceReference1.ServiceContractClient(httpBinding, endpoint);
//    public static ServiceClient.localhost.ServiceContractClient myClient = new ServiceClient.localhost.ServiceContractClient(httpBinding, endpoint);
    //A delegate that is used to asynchrounously talk
    //to the service when using the FAST METHOD
    public delegate void MyDelagate(String crudType);


    [SqlProcedure()]
    public static void SendData(String crudType)
    {

        /*A very simple procedure that accepts a string parameter 
          based on the CRUD action performed by the
          trigger. It switches based on this parameter 
          and calls the appropriate method on the service proxy*/

        switch (crudType)
        {
            case "Update":

                myclient.UpdateOccured();

                break;

            case "Insert":

                myclient.InsertOccured();
                break;
        }

    }

    [Microsoft.SqlServer.Server.SqlTrigger(Name = "WCFTrigger",
       Target = "tbCR", Event = "FOR UPDATE, INSERT")]
    public static void Trigger1()
    {
        /*This is a very basic trigger that performs two very simple actions:
         * 1) Gets the current trigger Context
         *    and then switches based on the triggeraction
         * 2) Makes a call to a stored procedure

         * Two methods of calling the stored procedure are presented here. 
         * View the article on Code Project for a discussion on these methods
         */

        SqlTriggerContext myContext = SqlContext.TriggerContext;
        //Used for the FAST METHOD
        MyDelagate d;

        switch (myContext.TriggerAction)
        {
            case TriggerAction.Update:

                //Slow method - NOT REMCOMMEND IN PRODUCTION!
                SendData("Update");

                //Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
                //d = new MyDelagate(SendData);
                //d.BeginInvoke("Update",null,null);

                break;

            case TriggerAction.Insert:

                //Slow method - NOT REMCOMMEND IN PRODUCTION!
                SendData("Insert");

                //Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
                //d = new MyDelagate(SendData);
                //d.BeginInvoke("Insert", null, null);

                break;

        }

    }

【问题讨论】:

  • 谢谢汉斯,我已经按照 Humanworkflow 中的建议做了,但我仍然有问题,看来我必须对我的 WCF 做点什么
  • 嗯,您在 Oleg 的回答中留下的评论表明您现在收到了完全不同的错误消息。 msdn.microsoft.com/en-us/library/ms403273.aspx
  • 基于少数博客,我强烈怀疑我必须不安全的一些组装,但无论你要求在“humanworkflow”中创建什么组装,它都是不安全的。我不知道我必须不安全的组装现在开始部署这个项目
  • 我再次重新检查安装在我的 sqlserver 中的程序集都是不安全的。

标签: c# sql-server triggers


【解决方案1】:

已明确说明 - 它需要 System.ServiceModel 程序集,但未提供。尝试先将此程序集(可能还有其他程序集)部署到 sql server

并尝试将您的静态字段作为局部变量移动到触发器主体中。

如果您将程序集标记为 UNSAFE 并将数据库标记为 TRUSTWORTHY - 可能无需这些修改即可工作

【讨论】:

  • 感谢 Oleg,但错误消息显示“CREATE ASSEMBLY 失败,因为安全程序集 'ServiceClient' 中的类型 'Triggers' 有一个静态字段 'endpoint'。” System.ServiceModel 已在 CLR 数据库项目中引用。如何部署此程序集?
  • 我在 SQL 中创建的“System.IdentityModel”程序集不过是 System.ServiceModel。到目前为止,我在 SQL 中创建了一个“SMDiagnostics,System.Web,System.Messaging,System.IdentityModel,System.IdentityModel.Selectors,Microsoft.Transactions.Bridge”程序集
  • 我所有的程序集都不安全,数据库也是值得信赖的。
  • 在我的服务 client.sql 中,我从 0x4D5A9000030 获得了这个 CREATE ASSEMBLY [ServiceClient] AUTHORIZATION [dbo](它的行数相当多,我只是为了向你们展示它而减少了它) WITH PERMISSION_SET = SAFE;我怎样才能将其更改为不安全。我相信可以解决我的问题或给 somthin 新的
  • 您还必须运行 ALTER DATABASE YourDBName SET TRUSTWORTHY ON
猜你喜欢
  • 2017-07-09
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 2015-06-07
  • 2020-01-07
  • 2023-02-08
  • 1970-01-01
相关资源
最近更新 更多