From version 2005 sqlclr is build in MS Sql Server, with this presentation from Macedonian Code Camp 2013 (http://codecamp.mk), we want to show what we learned thru the years of using it.
6. Agenda
Why SQL CLR?
What Is Assembly and How To Get Info About?
Demo1
Create CLR Functions
Demo 2
Discussion
Encrypt/Decrypt
7. Why SQL CLR?
A better programming model
Improved safety and security
Ability to define data types and aggregate
functions
Streamlined development through a
standardized environment
Potential for improved performance and
scalability
8. What Is Assembly
Assemblies are DLL files used in an
instance of SQL Server to deploy:
Functions
Stored procedures
Triggers
User-defined aggregates
User-defined types
9. Getting Info About Assemblies
ASSEMBLYPROPERTY('assembly_name', 'property_name')
14. SQL Server In-Process Specific
Extensions to ADO.NET
SqlContext Object This class provides access to the
other extensions by abstracting the context of a
caller of a SQL Server routine that executes managed
code in-process.
SqlPipe Object This class contains routines to send
tabular results and messages to the client.
SqlDataRecord Object The SqlDataRecord class
represents a single row of data, along with its related
metadata, and allows stored procedures to return
custom result sets to the client.
15. SqlTriggerContext Object This class provides information on the context in which a
trigger is run.
using System; using System.Data; using System.Data.Sql; using Microsoft.SqlServer.Server; using
System.Data.SqlClient; using System.Data.SqlTypes; using System.Xml; using
System.Text.RegularExpressions;
public class CLRTriggers
{
public static void DropTableTrigger()
{
SqlTriggerContext triggContext = SqlContext.TriggerContext;
switch(triggContext.TriggerAction)
{
case TriggerAction.DropTable:
SqlContext.Pipe.Send("Table dropped! Here's the EventData:");
SqlContext.Pipe.Send(triggContext.EventData.Value); break;
default: SqlContext.Pipe.Send("Something happened! Here's the
EventData:"); SqlContext.Pipe.Send(triggContext.EventData.Value);
break;
}
}
}
16. Returning Custom Result Set
Managed stored procedures can send result sets that do not
come from a SqlDataReader. The SendResultsStart method,
along with SendResultsRow and SendResultsEnd, allows stored
procedures to send custom result sets to the client.
SendResultsStart takes a SqlDataRecord as an input. It marks
the beginning of a result set and uses the record metadata to
construct the metadata that describes the result set. It does not
send the value of the record with SendResultsStart. All the
subsequent rows, sent using SendResultsRow, must match that
metadata definition.
23. Complete electronic evaluation forms on the
computers in the hall and enter to win!
Infragistics Ultimate
Telerik DevCraft
JetBrains .NET tools
Semos training vouchers
Pluralsight subscriptions
and many more