SlideShare a Scribd company logo
1 of 24
SQLCLR TIPS&TRICKS
Daniel Joskovski
Owner Omnis llc, Principal Developer Daenet,
MCT Semos Education
joskovski@t-home.mk
About me
Agenda
Why SQL CLR?
What Is Assembly and How To Get Info About?
Demo1
Create CLR Functions
Demo 2
Discussion
Encrypt/Decrypt
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
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
Getting Info About Assemblies
 ASSEMBLYPROPERTY('assembly_name', 'property_name')
• sys.assemblies
• sys.assembly_files
• sys.assembly_modules
Demo 1
Getting Info About Assemblies
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.
• 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;
}
}
}
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.
DEMO 2
Creating Managed Objects with Visual Studio
public static void TransactionHistoryRunningSum()
{
using (SqlConnection conn = new SqlConnection("context connection=true;"))
{
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = @"" +
"SELECT TransactionID, ActualCost " +
"FROM Production.TransactionHistory " +
"ORDER BY TransactionID";
SqlMetaData[] columns = new SqlMetaData[3];
columns[0] = new SqlMetaData("TransactionID", SqlDbType.Int);
columns[1] = new SqlMetaData("ActualCost", SqlDbType.Money);
columns[2] = new SqlMetaData("RunningTotal", SqlDbType.Money);
decimal RunningSum = 0;
SqlDataRecord record = new SqlDataRecord(columns);
SqlContext.Pipe.SendResultsStart(record);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
decimal ActualCost = (decimal)reader[1];
RunningSum += ActualCost;
record.SetInt32(0, (int)reader[0]);
record.SetDecimal(1, ActualCost);
record.SetDecimal(2, RunningSum);
SqlContext.Pipe.SendResultsRow(record);
}
SqlContext.Pipe.SendResultsEnd();
}
}
Discusion
Other way?
Ideas?
Supported Assemblies











Microsoft.Visualbasic.dll
Mscorlib.dll
System.Data.dll
System.dll
System.Xml.dll
Microsoft.Visualc.dll
Custommarshallers.dll
System.Security.dll
System.Web.Services.dll
System.Data.SqlXml.dll.
Demo
Creating PDF document in SQLCLR using IText
Documentation used
 http://msdn.microsoft.com/en-us/library/ms131102.aspx
 http://msdn.microsoft.com/en-us/library/ms131075.aspx
 http://msdn.microsoft.com/en-us/library/ms131070.aspx
• 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…
SQLCLR Tips & Trics

More Related Content

What's hot

Smidige databaser
Smidige databaserSmidige databaser
Smidige databaserKnut Haugen
 
Introduction to Unit Testing (Part 1 of 2)
Introduction to Unit Testing (Part 1 of 2)Introduction to Unit Testing (Part 1 of 2)
Introduction to Unit Testing (Part 1 of 2)Dennis Byrne
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-streamGaryCoady
 
The sql connection object
The sql connection objectThe sql connection object
The sql connection objectSharat Chandu
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
Data Access Technologies
Data Access TechnologiesData Access Technologies
Data Access TechnologiesDimara Hakim
 
SSMS-waitstats
SSMS-waitstatsSSMS-waitstats
SSMS-waitstatsE Blake
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...Otávio Santana
 
Sql injection invoker's right
Sql injection invoker's rightSql injection invoker's right
Sql injection invoker's rightGirija Muscut
 
DOCX_FileSavedAsOnBoxNet_28
DOCX_FileSavedAsOnBoxNet_28DOCX_FileSavedAsOnBoxNet_28
DOCX_FileSavedAsOnBoxNet_28Quickoffice Test
 

What's hot (17)

Smidige databaser
Smidige databaserSmidige databaser
Smidige databaser
 
T-SQL & Triggers
T-SQL & TriggersT-SQL & Triggers
T-SQL & Triggers
 
Java threading 2
Java threading 2Java threading 2
Java threading 2
 
Introduction to Unit Testing (Part 1 of 2)
Introduction to Unit Testing (Part 1 of 2)Introduction to Unit Testing (Part 1 of 2)
Introduction to Unit Testing (Part 1 of 2)
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-stream
 
The sql connection object
The sql connection objectThe sql connection object
The sql connection object
 
Grails basics
Grails basics Grails basics
Grails basics
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
04 Data Access
04 Data Access04 Data Access
04 Data Access
 
Data Access Technologies
Data Access TechnologiesData Access Technologies
Data Access Technologies
 
SSMS-waitstats
SSMS-waitstatsSSMS-waitstats
SSMS-waitstats
 
mediator
mediatormediator
mediator
 
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
MicroProfile: uma nova forma de desenvolver aplicações corporativas na era do...
 
Sql injection invoker's right
Sql injection invoker's rightSql injection invoker's right
Sql injection invoker's right
 
DOCX_FileSavedAsOnBoxNet_28
DOCX_FileSavedAsOnBoxNet_28DOCX_FileSavedAsOnBoxNet_28
DOCX_FileSavedAsOnBoxNet_28
 
Fetch data from form
Fetch data from formFetch data from form
Fetch data from form
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 

Similar to SQLCLR Tips & Trics

SQL Server - CLR integration
SQL Server - CLR integrationSQL Server - CLR integration
SQL Server - CLR integrationPeter Gfader
 
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)webhostingguy
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Netwebhostingguy
 
23 ijaprr vol1-3-25-31iqra
23 ijaprr vol1-3-25-31iqra23 ijaprr vol1-3-25-31iqra
23 ijaprr vol1-3-25-31iqraijaprr_editor
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And XmlDavid Truxall
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developerswebhostingguy
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hydewebhostingguy
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerCisco Canada
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsSalesforce Developers
 
System verilog important
System verilog importantSystem verilog important
System verilog importantelumalai7
 
05 entity framework
05 entity framework05 entity framework
05 entity frameworkglubox
 
Ordina SOFTC Presentation - SQL CLR
Ordina SOFTC Presentation - SQL CLROrdina SOFTC Presentation - SQL CLR
Ordina SOFTC Presentation - SQL CLROrdina Belgium
 

Similar to SQLCLR Tips & Trics (20)

SQL Server - CLR integration
SQL Server - CLR integrationSQL Server - CLR integration
SQL Server - CLR integration
 
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
 
Introduction to Threading in .Net
Introduction to Threading in .NetIntroduction to Threading in .Net
Introduction to Threading in .Net
 
23 ijaprr vol1-3-25-31iqra
23 ijaprr vol1-3-25-31iqra23 ijaprr vol1-3-25-31iqra
23 ijaprr vol1-3-25-31iqra
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developers
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hyde
 
CLR Stored Procedures
CLR Stored ProceduresCLR Stored Procedures
CLR Stored Procedures
 
Sql Server - Apresentação
Sql Server - ApresentaçãoSql Server - Apresentação
Sql Server - Apresentação
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
 
For Beginers - ADO.Net
For Beginers - ADO.NetFor Beginers - ADO.Net
For Beginers - ADO.Net
 
Mobile
MobileMobile
Mobile
 
Big Data Tools in AWS
Big Data Tools in AWSBig Data Tools in AWS
Big Data Tools in AWS
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data center
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
05 entity framework
05 entity framework05 entity framework
05 entity framework
 
Ordina SOFTC Presentation - SQL CLR
Ordina SOFTC Presentation - SQL CLROrdina SOFTC Presentation - SQL CLR
Ordina SOFTC Presentation - SQL CLR
 

Recently uploaded

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

SQLCLR Tips & Trics

  • 1.
  • 2. SQLCLR TIPS&TRICKS Daniel Joskovski Owner Omnis llc, Principal Developer Daenet, MCT Semos Education joskovski@t-home.mk
  • 3.
  • 4.
  • 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')
  • 13. Demo 1 Getting Info About Assemblies
  • 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.
  • 17. DEMO 2 Creating Managed Objects with Visual Studio
  • 18. public static void TransactionHistoryRunningSum() { using (SqlConnection conn = new SqlConnection("context connection=true;")) { SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = @"" + "SELECT TransactionID, ActualCost " + "FROM Production.TransactionHistory " + "ORDER BY TransactionID"; SqlMetaData[] columns = new SqlMetaData[3]; columns[0] = new SqlMetaData("TransactionID", SqlDbType.Int); columns[1] = new SqlMetaData("ActualCost", SqlDbType.Money); columns[2] = new SqlMetaData("RunningTotal", SqlDbType.Money); decimal RunningSum = 0; SqlDataRecord record = new SqlDataRecord(columns); SqlContext.Pipe.SendResultsStart(record); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { decimal ActualCost = (decimal)reader[1]; RunningSum += ActualCost; record.SetInt32(0, (int)reader[0]); record.SetDecimal(1, ActualCost); record.SetDecimal(2, RunningSum); SqlContext.Pipe.SendResultsRow(record); } SqlContext.Pipe.SendResultsEnd(); } }
  • 21. Demo Creating PDF document in SQLCLR using IText
  • 22. Documentation used  http://msdn.microsoft.com/en-us/library/ms131102.aspx  http://msdn.microsoft.com/en-us/library/ms131075.aspx  http://msdn.microsoft.com/en-us/library/ms131070.aspx
  • 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…