Tuesday, July 3, 2012

Create CLR Trigger


Steps for creating CLR Trigger


Follow these steps to create a CLR trigger of DML (after) type to perform an insert action:
Create a .NET class of triggering action
Make an assembly (.DLL) from that Class
Enable CLR environment in that database.
Register the assembly in SQL Server
Create CLR Trigger using that assembly

CLR Triggers

CLR Triggers


A CLR trigger could be a Date Definition or Date Manipulation Language trigger or could be an AFTER or INSTEAD OF trigger. Methods written in managed codes that are members of an assembly need to be executed provided the assembly is deployed in SQL 2005 using the CREATE assembly statement. The Microsoft.SqlServer.Server Namespace contains the required classes and enumerations for this objective.

Custom Exceptions


What are Custom Exceptions?


Custom Exceptions are user defined exceptions. There are exceptions other than the predefined ones which need to be taken care of. For example, The rules for the minimum balance in a Salary A/C would be different from that in a Savings A/C due to which these things need to be taken care of during the implementation.


Implement Delegates in C#.NET


Explain how to implement Delegates in C#.NET?


Here is an implementation of a very simple delegate that accepts no parameters.


public delegate void MyDelegate();// Declaration
class MyClass
{
     public static void MyFunc()
     {
         Console.WriteLine("MyFunc Called from a Delegate");
     }
     public static void Main()
     {
            MyDelegate myDel = new MyDelegate(MyFunc);
            myDel();
      }
}


What is assembly in .NET


Define assembly.


An assembly is the primary unit of a .NET application. It includes an assembly manifest that describes the assembly.