CLR Stored Procedures<br />HarshanaWeerasinghe<br />http://about.me/harshana<br />
Agenda<br />SQL CLR<br />CLR Stored Procedures<br />The Need For CLR Stored Procedures<br />Drawbacks<br />Configuration <...
SQL CLR ?<br /> Is the technology that hosts the Microsoft .NET Common Language Runtime engine within SQL Server.<br />SQL...
CLR Stored Procedures<br />Similar to normal Stored Procedures, but code written using Microsoft .NET (C#, VB.NET or any l...
The Need For CLR Stored Procedures<br />Gives better results while executing complex logic:<br /> Intense string operation...
The Need For CLR Stored Procedures<br />Better code management<br />Provides object oriented programming<br />Encapsulatio...
Drawbacks<br />Not convenient in all scenarios<br />E.g. they should not be used to execute simple queries.<br />Deploymen...
Configuration<br />Enable CLR in SQL Server<br />
How to use (demo)<br />SqlPipe<br />Debug<br />Send SQL query as a result<br />Custom Result Sets<br />Single record<br />...
Errors When Debugging<br />
External Access<br />
External Access (demo)<br />
Serialization Errors<br />“Cannot load dynamically generated serialization assembly”<br />Add post build event<br />"C:Pro...
Deployment<br />Deploy assembly<br />SP <br />
Q & A<br />What Sgen.exe does ?<br />The XML Serializer Generator creates an XML serialization assembly for types in a spe...
Q & A<br />What is the deference between PERMISSION_SET SAFE, EXTERNAL_ACCESS and UNSAFE ? <br />Code executed by an assem...
Q & A<br />List down Benefits of using CLR Stored Procedures<br />See the “The Need For CLR Stored Procedures” in presenta...
References<br />http://msdn.microsoft.com/en-us/library/ms131094.aspx - CLR Stored Procedures<br />
Thank you<br />
Upcoming SlideShare
Loading in...5
×

CLR Stored Procedures

844

Published on

Presentation I used in JAN monthly meetup on SQL Server Universe community (http://www.sqlserveruniverse.com).

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
844
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  •  TRUSTWORTHY : indicate whether the instance of SQL Server trusts the database and the contents within it.
  • CLR Stored Procedures

    1. 1. CLR Stored Procedures<br />HarshanaWeerasinghe<br />http://about.me/harshana<br />
    2. 2. Agenda<br />SQL CLR<br />CLR Stored Procedures<br />The Need For CLR Stored Procedures<br />Drawbacks<br />Configuration <br />How to use (demo)<br />Debugging SQL CLR DLLs<br />External Access<br />External Access (demo)<br />Deployment<br />
    3. 3. SQL CLR ?<br /> Is the technology that hosts the Microsoft .NET Common Language Runtime engine within SQL Server.<br />SQLCLR allows managed code to be hosted by, and run in, the Microsoft SQL Server environment<br />
    4. 4. CLR Stored Procedures<br />Similar to normal Stored Procedures, but code written using Microsoft .NET (C#, VB.NET or any language in .NET)<br />Works as an MSIL assembly integrated with the SQL Engine.<br />
    5. 5. The Need For CLR Stored Procedures<br />Gives better results while executing complex logic:<br /> Intense string operations/string manipulation<br />Cryptography<br />Accessing system resources<br />File Management<br />CLR Stored Procedures are managed code<br />Ensures type safety<br />Ensures memory management<br />
    6. 6. The Need For CLR Stored Procedures<br />Better code management<br />Provides object oriented programming<br />Encapsulation<br />Polymorphism<br />Inheritance<br />Can be written using<br />C#<br />VB<br />Any other language that the .NET Framework supports<br />
    7. 7. Drawbacks<br />Not convenient in all scenarios<br />E.g. they should not be used to execute simple queries.<br />Deployment may be difficult in some scenarios.<br />
    8. 8. Configuration<br />Enable CLR in SQL Server<br />
    9. 9. How to use (demo)<br />SqlPipe<br />Debug<br />Send SQL query as a result<br />Custom Result Sets<br />Single record<br />Multiple records (SendResultsStart, SendResultsRow, SendResultsEnd)<br /><ul><li>Connection String</li></ul>ADO.NET<br />
    10. 10. Errors When Debugging<br />
    11. 11. External Access<br />
    12. 12. External Access (demo)<br />
    13. 13. Serialization Errors<br />“Cannot load dynamically generated serialization assembly”<br />Add post build event<br />"C:Program Files (x86)Microsoft Visual Studio 8SDKv2.0Binsgen.exe" /force "$(TargetPath)"<br />More information : http://support.microsoft.com/kb/913668<br />
    14. 14. Deployment<br />Deploy assembly<br />SP <br />
    15. 15. Q & A<br />What Sgen.exe does ?<br />The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializesobjects of the specified types.<br />
    16. 16. Q & A<br />What is the deference between PERMISSION_SET SAFE, EXTERNAL_ACCESS and UNSAFE ? <br />Code executed by an assembly with SAFE permissions cannot access external system resources such as files, the network, environment variables, or the registryand EXTERNAL_ACCESS can access.<br />UNSAFE enables assemblies unrestricted access to resources, both within and outside an instance of SQL Server. Code running from within an UNSAFE assembly can call unmanaged code. <br />
    17. 17. Q & A<br />List down Benefits of using CLR Stored Procedures<br />See the “The Need For CLR Stored Procedures” in presentation.<br />
    18. 18. References<br />http://msdn.microsoft.com/en-us/library/ms131094.aspx - CLR Stored Procedures<br />
    19. 19. Thank you<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×