SQL CLR error

  • I have SQL CLR project with following method.

    Microsoft.SqlServer.Server.SqlTrigger(Name:="AuditCommon", Event:="FOR UPDATE, INSERT, DELETE")

    Public Shared Sub AuditCommon()

    I am getting error as mentioned below.

    ErrorThe method "AuditCommon" in class "AuditCommon.Triggers" marked as a trigger is missing a target and/or event specification.AuditCommon

    Could anyone please help me

  • ritesh.saluja (12/10/2008)


    I have SQL CLR project with following method.

    Microsoft.SqlServer.Server.SqlTrigger(Name:="AuditCommon", Event:="FOR UPDATE, INSERT, DELETE")

    Public Shared Sub AuditCommon()

    I am getting error as mentioned below.

    ErrorThe method "AuditCommon" in class "AuditCommon.Triggers" marked as a trigger is missing a target and/or event specification.AuditCommon

    Could anyone please help me

    As the error states, you are missing the Target: specification in the Microsoft.SqlServer.Server.SqlTrigger Attribute. You can't use CLR to violate the requirement that a trigger exists on one and only one table. You are still going to have to write a separate trigger for every table, just as you would in TSQL, and for audit purposes, TSQL will outperform SQLCLR consistently.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • You can find an example trigger in the Books Online:

    http://msdn.microsoft.com/en-us/library/938d9dz2(VS.80).aspx

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • thanks for reply. I am looking at someone else's code. And seen the code comment.

    ' This is the original template for Trigger metadata. Note that it is table-specific (i.e. it suggests

    ' that the trigger should apply to one table only).

    ' Microsoft.SqlServer.Server.SqlTrigger(Name:="Trigger1", Target:="Table1", Event:="FOR UPDATE") _

    ' This is our actual declaration. Note that it does not specify any particular table. We don't know

    ' if it is Microsoft's intention to allow table-agnostic trigger code, but this works and we hope

    ' that it keeps working.

    So does it mean that code will work on some specific version of VS.Net

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply