clr stored procedures

19
Harshana Weerasinghe http://about.me/harshana

Upload: harshana-weerasinghe

Post on 04-Jul-2015

856 views

Category:

Technology


5 download

DESCRIPTION

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

TRANSCRIPT

Page 1: CLR Stored Procedures

Harshana Weerasinghehttp://about.me/harshana

Page 2: CLR Stored Procedures

SQL CLR

CLR Stored Procedures

The Need For CLR Stored

Procedures

Drawbacks

Configuration

How to use (demo)

Debugging SQL CLR DLLs

External Access

External Access (demo)

Deployment

Page 3: CLR Stored Procedures

Is the technology that hosts the Microsoft .NET Common Language Runtime engine within SQL Server.

SQLCLR allows managed code to be hosted by, and run in, the Microsoft SQL Server environment

Page 4: CLR Stored Procedures

Similar to normal Stored Procedures, but code written using Microsoft .NET (C#, VB.NET or any language in .NET)

Works as an MSIL assembly integrated with the SQL Engine.

Page 5: CLR Stored Procedures

Gives better results while executing complex logic: Intense string operations/string manipulation

Cryptography

Accessing system resources

File Management

CLR Stored Procedures are managed code Ensures type safety

Ensures memory management

Page 6: CLR Stored Procedures

Better code management

Provides object oriented programming Encapsulation

Polymorphism

Inheritance

Can be written using C#

VB

Any other language that the .NET Framework supports

Page 7: CLR Stored Procedures

Not convenient in all scenarios

E.g. they should not be used to execute simple queries.

Deployment may be difficult in some scenarios.

Page 8: CLR Stored Procedures

Enable CLR in SQL Server

Page 9: CLR Stored Procedures

SqlPipe Debug Send SQL query as a result Custom Result Sets

Single record

Multiple records (SendResultsStart, SendResultsRow, SendResultsEnd)

Connection String ADO.NET

Page 10: CLR Stored Procedures
Page 11: CLR Stored Procedures
Page 12: CLR Stored Procedures
Page 13: CLR Stored Procedures

“Cannot load dynamically generated serialization assembly”

Add post build event

"C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /force "$(TargetPath)"

More information :http://support.microsoft.com/kb/913668

Page 14: CLR Stored Procedures

Deploy assembly

SP

Page 15: CLR Stored Procedures

What Sgen.exe does ?

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 deserializes objects of the specified types.

Page 16: CLR Stored Procedures

What is the deference between PERMISSION_SET SAFE, EXTERNAL_ACCESS and UNSAFE ? Code executed by an assembly with SAFE permissions cannot access

external system resources such as files, the network, environment variables, or the registry and EXTERNAL_ACCESS can access.

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.

Page 17: CLR Stored Procedures

List down Benefits of using CLR Stored Procedures

See the “The Need For CLR Stored Procedures” in presentation.

Page 19: CLR Stored Procedures