Discussion:
CLR Trigger Error: Could not find Type xxxx in Assembly
(too old to reply)
Trex
2006-02-01 18:22:44 UTC
Permalink
I've got the following code (C# code) but when I execute the Create Trigger
statement I get the error

"Could not find Type 'InheritanceTriggers' in assembly 'CLRTriggers'

I believe I'm satisfying all the rules: the class is public, the method is
public, and the method is static.

Anythoughts?

Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name CLRTriggers.InheritanceTriggers.EnforceBaseObject
GO

CLRTriggers.dll code below

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;

namespace My.SQLServer
{
public class InheritanceTriggers
{
[SqlTrigger(Name = @"EnforceInheritanceTrigger", Target =
"[dbo].[Person]", Event = "FOR INSERT")]
public static void EnforceBaseObject()
{
SqlTriggerContext context = SqlContext.TriggerContext;
String SQLForInserted = "SELECT * FROM INSERTED;";
string ATableName = "dbo.Person";

if (context.TriggerAction == TriggerAction.Insert)
{

using (SqlConnection connection
= new SqlConnection(@"context connection=true"))
{
connection.Open();
SqlCommand command = new SqlCommand(SQLForInserted,
connection);
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
System.Guid id = (System.Guid)reader[0];
string s = <sql statement is here>;
SqlCommand command1 = new SqlCommand(s, connection);
SqlPipe pipe = SqlContext.Pipe;
pipe.Send(s);
}
reader.Close();
}
}
}

}
}
Steven Hemingray [MSFT]
2006-02-01 18:46:01 UTC
Permalink
Post by Trex
Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.InheritanceTriggers.EnforceBaseObject
You need to include your namespace:

Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.[My.SQLServer.InheritanceTriggers].EnforceBaseObject

Steven
Trex
2006-02-01 19:54:42 UTC
Permalink
Unfortunately, that still didn't help:

Could not find Type 'My.SQLServer.InheritanceTriggers' in assembly
'CLRTriggers'.

but thanks for the suggestion...at least it gave me something new to try. :)
Post by Trex
Post by Trex
Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.InheritanceTriggers.EnforceBaseObject
Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.[My.SQLServer.InheritanceTriggers].EnforceBaseObject
Steven
Trex
2006-02-01 20:25:27 UTC
Permalink
I beg your pardon! I got my namespaces mixed up and you are absolutely
correct! Thank you Steve H! (I'll bet you were saying to yourself, "this
guy's nuts", I know that's the problem) :)
Post by Trex
Post by Trex
Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.InheritanceTriggers.EnforceBaseObject
Create Trigger EnforceInheritanceTrigger on [Person]
For INSERT as External Name
CLRTriggers.[My.SQLServer.InheritanceTriggers].EnforceBaseObject
Steven
ryand
2012-06-19 08:10:10 UTC
Permalink
Trex wrote on 02/01/2006 15:25 ET
Post by Trex
I beg your pardon! I got my namespaces mixed up and you are absolutel
correct! Thank you Steve H! (I'll bet you were saying to yourself, "thi
Post by Steven Hemingray [MSFT]
Post by Trex
Create Trigger EnforceInheritanceTrigger on [Person
For INSERT as External Nam
CLRTriggers.InheritanceTriggers.EnforceBaseObjec
You need to include your namespace
Create Trigger EnforceInheritanceTrigger on [Person
For INSERT as External Nam
CLRTriggers.[My.SQLServer.InheritanceTriggers].EnforceBaseObjec
Steve
This was extremely helpful!!! I was having the exact same issue and afte
reading this article I was good to go. I pasted by SQL trigger code as well s
others can see more examples just in case. Thanks again for posting this, i
saved me a truck load of time. I had already been researching this for an hou
before I came across this post

-------------------

CREATE TRIGGER trigger_clr3
ON MY_TABL
FOR INSER
A
EXTERNAL NAME train_assembly.[CLR_Trigger_35.CLR_Trigger_35].SQLTriggerCall
Loading...