SlideShare a Scribd company logo
Where .NET meets SQL Server… SQL CLRJurgen Asselman.NET and SQL Server Consultantjurgen.asselman@ordina.be
About me…Jurgen Asselman14 years of experience in IT@Ordina since 2007Before Ordina +7 years @Sony .NET and SQL Server Consultant @EliaMCIT PRO SQL Server 20082
AgendaAbout SQL CLRBenefitsWhat can it be used for?The permissions overviewInstallation of a CLR assemblyThe configuration issue…Tips & tricksWhen to use SQL CLRConclusion3
About SQL CLRHosting Microsoft .NET Framework in SQL Server EngineRun managed code in your databaseAlternative forExtended Stored ProceduresCOM AutomationComplex T-SQL algoritmsxp_cmdshellDoes NOT replace T-SQL nor DBAs4SQL EngineCLRHostingLayerSQL OS LayerWindows OS
BenefitsLarger programmer productivityEnhanced programming modelEnhanced safety and securityCommon development environmentPerformance and scalability5
What can it be used for?Stored Procedures (SP)TriggersUser-Defined Functions (UDF)User Defined Aggregates (UDA)User Defined Types (UDT)6
Demo timeCreate a User Defined Function, a Stored Procedure and a User Defined Type7
The permissions overviewSAFEAllows data access, basic librariesEXTERNAL_ACCESSAllows access to IO librariesUNSAFEAllows access to unmanaged code8
Installation of a CLR assemblyBy default SQL CLR is turned off  turn it onVia T-SQL SSMSInstall your assemblies viaT-SQLSSMS9
Demo timeEnable SQL CLRInstall our created assembly10
The configuration issue…The .config file as we know it in .NET developmentin sqlserver.exe.config!change configuration items  restart your SQL ServerBest practiceconfiguration table in which keys and values are stored11
Tips & tricks	Enable SQL CLR on your database serverEXECsp_configure‘clr enabled’, 1RECONFIGURE   GO12
Tips & tricks	When you create your CLR UDF or Stored Procedure the T-SQL way, take a look at this syntaxCREATE[ FUNCTION / STORED PROCEDURE / TRIGGER … ]({parameters})[RETURNS {return value}]AS     EXTERNAL NAME [Assembly].[Namespace].[Function]13
Tips & tricks	Using a connection string in the stored procedure, when connecting to the current databaseusing(SqlConnection connection = newSqlConnection("context connection=true"))        {//your code here        }14
When to use SQL CLRDo I need to manipulate data before it is displayed?.NET code and SQL CLRDo I need to do set-based operations?T-SQLDo I need to do extensive calculations or custom algorithms?.NET code and SQL CLRAre my developers SQL gurus but .NET newbiesT-SQLDo I have loads of stored procedures that are hard to manage?.NET code and SQL CLR15
Demo timeUse our created and installed assembly in SQL Server16
ConclusionSQL CLR is a powerful featureAdvantagesUse .NET base-class-libraryImplement Complex CodeInterface with external resourcesCautionDoesn’t replace T-SQL17
Questions?18
Want to know more? Contact Jurgen AsselmanEmail:  jurgen.asselman@ordina.beBlog: http://jurgenasselman.blogspot.comTwitter: @jurgenasselman19
Follow Ordina…20Share your thoughts via #SOFTC Follow us on twitter: @OrdinaBEFind the presentationsonwww.slideshare.net/ordinaBeBe informed atwww.linkedin.com/company/ordina-belgium

More Related Content

PPTX
Ordina SOFTC Presentation - Async CTP
PDF
Ansible for networks
PDF
Docker-Vancouver Meetup - March 18, 2014 - Contain(erize) the tests - Mark Ei...
PDF
Ansible 2.2
PDF
F5 Automation and service discovery
PDF
Quick and Solid - Baremetal on OpenStack | Rico Lin
PPTX
Nodejs intro
PDF
Ansible container
Ordina SOFTC Presentation - Async CTP
Ansible for networks
Docker-Vancouver Meetup - March 18, 2014 - Contain(erize) the tests - Mark Ei...
Ansible 2.2
F5 Automation and service discovery
Quick and Solid - Baremetal on OpenStack | Rico Lin
Nodejs intro
Ansible container

What's hot (20)

PPTX
Introduction to Node js
PDF
Introduction to node js - From "hello world" to deploying on azure
PPTX
CLI utility in ClojureScript running on Node.js
PDF
Deploying nginx with minimal system resources
PDF
Ansible-for-openstack
PDF
Whatthestack using Tempest for testing your OpenStack deployment
PPTX
Node js introduction
PDF
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
PDF
VMware compute driver for OpenStack
PDF
PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...
PPT
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
PPTX
Node js Introduction
DOCX
Oracle WebLogic
PDF
Ansible testing
PDF
Ansible best practices
PDF
CloudOps CloudStack Days, Austin April 2015
PPTX
Node js training (1)
PPT
Node.js Cloud deployment
PDF
HKG15-204: OpenStack: 3rd party testing and performance benchmarking
PPTX
Java App On Digital Ocean: Deploying With Gitlab CI/CD
Introduction to Node js
Introduction to node js - From "hello world" to deploying on azure
CLI utility in ClojureScript running on Node.js
Deploying nginx with minimal system resources
Ansible-for-openstack
Whatthestack using Tempest for testing your OpenStack deployment
Node js introduction
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
VMware compute driver for OpenStack
PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...
SDC - Programming the CLR in SQL Server 2005.ppt (1.51 MB)
Node js Introduction
Oracle WebLogic
Ansible testing
Ansible best practices
CloudOps CloudStack Days, Austin April 2015
Node js training (1)
Node.js Cloud deployment
HKG15-204: OpenStack: 3rd party testing and performance benchmarking
Java App On Digital Ocean: Deploying With Gitlab CI/CD
Ad

Similar to Ordina SOFTC Presentation - SQL CLR (20)

PDF
23 ijaprr vol1-3-25-31iqra
PPT
SQL Server 2005 CLR Integration
PPT
SQLCLR For DBAs and Developers
PPT
Dr. Jekyll and Mr. Hyde
PPT
Introduction to Threading in .Net
PPTX
SQL Server - CLR integration
PPT
Sql Summit Clr, Service Broker And Xml
PDF
Professional Sql Server 2005 Clr Programming With Stored Procedures Functions...
PPT
ow.ppt
PPT
kjdiakdnfdifjadsjkjklljlldasgjdjdljgfldjgldjgldjgl.ppt
PPTX
SQLCLR Tips & Trics
PDF
Sql Server - Apresentação
PPT
ow-123123123123123123123123123123123123123
PPTX
Object relational database management system
PPTX
CLR Stored Procedures
PPT
Plantilla oracle
PDF
Professional sql server 2005 clr programming
PPT
Rajnish singh(presentation on oracle )
23 ijaprr vol1-3-25-31iqra
SQL Server 2005 CLR Integration
SQLCLR For DBAs and Developers
Dr. Jekyll and Mr. Hyde
Introduction to Threading in .Net
SQL Server - CLR integration
Sql Summit Clr, Service Broker And Xml
Professional Sql Server 2005 Clr Programming With Stored Procedures Functions...
ow.ppt
kjdiakdnfdifjadsjkjklljlldasgjdjdljgfldjgldjgldjgl.ppt
SQLCLR Tips & Trics
Sql Server - Apresentação
ow-123123123123123123123123123123123123123
Object relational database management system
CLR Stored Procedures
Plantilla oracle
Professional sql server 2005 clr programming
Rajnish singh(presentation on oracle )
Ad

More from Ordina Belgium (15)

PPTX
Ordina SOFTC Presentation - UsingGeoData_ReportBuilder
PPTX
Ordina SOFTC Presentation - SharePoint - Automated scripted deployment
PPTX
Ordina SOFTC Presentation - Developing against SharePoint 2010 Lists
PPTX
Ordina SOFTC Presentation - SharePoint 2010 Architecture
PPTX
Ordina SOFTC Presentation - Office 365
PPTX
Ordina SOFTC Presentation - Desktop Virtualization
PPTX
Ordina SOFTC Presentation - Demand management using workflow Project Server 2010
PPTX
Ordina SOFTC Presentation - Demand management using workflow Project Server 2010
PPTX
Ordina SOFTC Presentation - Bridging the project and work management gap
PPTX
Ordina SOFTC Presentation - Visual Studio LightSwitch
PPTX
Ordina SOFTC Presentation - Building a WP7 app - Lessons learned
PPTX
Ordina SOFTC Presentation - Windows Phone 7 and the cloud
PPTX
Ordina SOFTC Presentation - Moving a legacy application into the cloud
PPTX
Ordina SOFTC Presentation - Deployment with TFS Build and Workflow
PPTX
Ordina SOFTC Presentation - TFS and JAVA, better together
Ordina SOFTC Presentation - UsingGeoData_ReportBuilder
Ordina SOFTC Presentation - SharePoint - Automated scripted deployment
Ordina SOFTC Presentation - Developing against SharePoint 2010 Lists
Ordina SOFTC Presentation - SharePoint 2010 Architecture
Ordina SOFTC Presentation - Office 365
Ordina SOFTC Presentation - Desktop Virtualization
Ordina SOFTC Presentation - Demand management using workflow Project Server 2010
Ordina SOFTC Presentation - Demand management using workflow Project Server 2010
Ordina SOFTC Presentation - Bridging the project and work management gap
Ordina SOFTC Presentation - Visual Studio LightSwitch
Ordina SOFTC Presentation - Building a WP7 app - Lessons learned
Ordina SOFTC Presentation - Windows Phone 7 and the cloud
Ordina SOFTC Presentation - Moving a legacy application into the cloud
Ordina SOFTC Presentation - Deployment with TFS Build and Workflow
Ordina SOFTC Presentation - TFS and JAVA, better together

Ordina SOFTC Presentation - SQL CLR

  • 1. Where .NET meets SQL Server… SQL CLRJurgen Asselman.NET and SQL Server Consultantjurgen.asselman@ordina.be
  • 2. About me…Jurgen Asselman14 years of experience in IT@Ordina since 2007Before Ordina +7 years @Sony .NET and SQL Server Consultant @EliaMCIT PRO SQL Server 20082
  • 3. AgendaAbout SQL CLRBenefitsWhat can it be used for?The permissions overviewInstallation of a CLR assemblyThe configuration issue…Tips & tricksWhen to use SQL CLRConclusion3
  • 4. About SQL CLRHosting Microsoft .NET Framework in SQL Server EngineRun managed code in your databaseAlternative forExtended Stored ProceduresCOM AutomationComplex T-SQL algoritmsxp_cmdshellDoes NOT replace T-SQL nor DBAs4SQL EngineCLRHostingLayerSQL OS LayerWindows OS
  • 5. BenefitsLarger programmer productivityEnhanced programming modelEnhanced safety and securityCommon development environmentPerformance and scalability5
  • 6. What can it be used for?Stored Procedures (SP)TriggersUser-Defined Functions (UDF)User Defined Aggregates (UDA)User Defined Types (UDT)6
  • 7. Demo timeCreate a User Defined Function, a Stored Procedure and a User Defined Type7
  • 8. The permissions overviewSAFEAllows data access, basic librariesEXTERNAL_ACCESSAllows access to IO librariesUNSAFEAllows access to unmanaged code8
  • 9. Installation of a CLR assemblyBy default SQL CLR is turned off  turn it onVia T-SQL SSMSInstall your assemblies viaT-SQLSSMS9
  • 10. Demo timeEnable SQL CLRInstall our created assembly10
  • 11. The configuration issue…The .config file as we know it in .NET developmentin sqlserver.exe.config!change configuration items  restart your SQL ServerBest practiceconfiguration table in which keys and values are stored11
  • 12. Tips & tricks Enable SQL CLR on your database serverEXECsp_configure‘clr enabled’, 1RECONFIGURE GO12
  • 13. Tips & tricks When you create your CLR UDF or Stored Procedure the T-SQL way, take a look at this syntaxCREATE[ FUNCTION / STORED PROCEDURE / TRIGGER … ]({parameters})[RETURNS {return value}]AS EXTERNAL NAME [Assembly].[Namespace].[Function]13
  • 14. Tips & tricks Using a connection string in the stored procedure, when connecting to the current databaseusing(SqlConnection connection = newSqlConnection("context connection=true")) {//your code here }14
  • 15. When to use SQL CLRDo I need to manipulate data before it is displayed?.NET code and SQL CLRDo I need to do set-based operations?T-SQLDo I need to do extensive calculations or custom algorithms?.NET code and SQL CLRAre my developers SQL gurus but .NET newbiesT-SQLDo I have loads of stored procedures that are hard to manage?.NET code and SQL CLR15
  • 16. Demo timeUse our created and installed assembly in SQL Server16
  • 17. ConclusionSQL CLR is a powerful featureAdvantagesUse .NET base-class-libraryImplement Complex CodeInterface with external resourcesCautionDoesn’t replace T-SQL17
  • 19. Want to know more? Contact Jurgen AsselmanEmail: jurgen.asselman@ordina.beBlog: http://jurgenasselman.blogspot.comTwitter: @jurgenasselman19
  • 20. Follow Ordina…20Share your thoughts via #SOFTC Follow us on twitter: @OrdinaBEFind the presentationsonwww.slideshare.net/ordinaBeBe informed atwww.linkedin.com/company/ordina-belgium

Editor's Notes

  • #5: Technology for hosting the Microsoft .NET Common Language Runtime engine within SQL Server.Allows managed code to be hosted by and run in the Microsoft SQL Server environment.Alternative for T-SQL and XpsReplace Extended SP’s with a safer alternativeReplace COM automation: sp_OA_*Complex T-SQL algoritmsrecommended replacement for xp_cmdshellT-SQLDevelopers should view the CLR as an efficient alternative for logic that cannot be expressed declaratively in the query languageFor all the other logic, T-SQL will be sufficient.Hosting layer provides coordination of:Assembly LoadingMemory managementSecurity ModelReliabilityThreads & FibersDeadlock detectionExecution context
  • #6: Bigger Programmer productivity.Enhanced programming model: .NET Framework languages are richer than T-SQL ,offering capabilities not available to SQL developers. Enhanced safety and security: Managed code runs in a CLR environment, hosted by the database engine. Allows .NET Framework database objects to be safer and more secure than extended stored procedures.Common development environment:Database development integrated into Visual Studio development environment. same tools available for dev and debugging as in other .NET devs.Performance and scalability:managed code compiles to native code prior to execution, => significant performance increases in some scenarios.
  • #7: Stored procedures (SPs) which are analogous to procedures or void functions in procedural languages like VB or C,triggers which are stored procedures that fire in response to Data Manipulation Language (DML) or Data Definition Language (DDL) events,User-defined functions (UDFs) => scalare and table functions, which are analogous to functions in procedural languages,User-defined aggregates (UDAs) which allow developers to create custom aggregates that act on sets of data instead of one row at a time,User-defined types (UDTs) that allow users to create simple or complex data types which can be serialized and deserialized within the database
  • #8: Function => 1 Scalar => regex function 2 table valuedStored procedure => Read csv files on a shared location and load the data into the database Example: A company has several store locations. Each location has a disconnected ticking system, out of which CSV files with personall ticking times are generated. These files are then posted on an FTP server. \\\\ord01170\\Tickings is the share to the shared locationEmployeeTickings is the table to insert inOur CLR stored procedure will read the files on the shared directory and upload them into the central system in order to calculate the hours worked by personnel. UDT = > currency
  • #9: Be very carfull when using UNSAFE, you can do anything with it, so KNOW YOUR CODE!
  • #10: Short demo showing turning on SQLCLR in SSMSBy default CLR Integration is turned offTurn on via the Surface Area Configuration Manager, orRight-Click Database ServerSelect FacetsSelect Surface Area ConfigurationSet ClrIntegrationEnabled to TrueTransact SQL (T-SQL) Assembly InstallationOnce we have coded our C# assembly, we need to get it installed onto our SQL Server instance.The following steps need to be executed to install your CLR Code into SQL ServerAllow SQL Server to run CLR CodeWrite you code in C# or Vb.netCompile your codeLoad the assembly into SQL ServerCreate the database object and point it to the assemblySince we create our examples in Visual Studio, deployment of CLR assemblies to your database is even made easier. When you have created your code, you can compile and just Right Click and the Select DEPLOY in your project. (I will demonstrate this.)CREATE ASSEMBLY CLRDemo FROM 'C:\\MyAssemblyPath\\CLRDemo.dll'WITH PERMISSION_SET = SAFE;
  • #11: Demo it via T-SQL and via SSMS
  • #12: Like in all other .NET developments, you can set configurations to be used in your assemblies…In sql clr, configuration can always be done like we know it in genuine .NET develepment…. By using a configuration file.However, since we are in SQL Clr, the assembly is uploaded into a SQL Server database, where it is stored in the system catalogs using the CREATE ASSEMBLY data definition language (DDL) statement.This has the nasty side effect that we can only use the configuration file when it is called sqlserver.exe.config!In order to get the configuration even to work for our assemblies, we need to restart the SQL ServerIf you do not want to have your production server rebooted each time you deploy configuration changes, there is a better practice to have your configuration done in a dynamic way. Use a table, which you can call configuration for example and store your keys and values in there. This way, you can add, change configuration keys when necessary, without having to restart your SQL Server.
  • #16: When you decide to look at CLR, you can ask yourself some of the following questions, to help you decide wether or not you should use CLR...Set based: Selecting, filtering, sorting Versioning