SQL Server 2005 and the SQL Server 2005 and the CLR: CLR: What do you need to know? What do you need to know? Randy Holloway Randy Holloway Solution Specialist- App Plat & Solution Specialist- App Plat & Dev Dev Microsoft Corporation Microsoft Corporation
20
Embed
SQL Server 2005 and the CLR: What do you need to know?
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
SQL Server 2005 and the CLR:SQL Server 2005 and the CLR:What do you need to know?What do you need to know?
Randy HollowayRandy HollowaySolution Specialist- App Plat & DevSolution Specialist- App Plat & Dev
Microsoft CorporationMicrosoft Corporation
Speaker – Randy HollowaySpeaker – Randy Holloway
Former IT Director and Software Former IT Director and Software Development ManagerDevelopment Manager
Author of over thirty articles on .NET, Author of over thirty articles on .NET, SQL Server and other Microsoft SQL Server and other Microsoft technologiestechnologies
Author of two upcoming booksAuthor of two upcoming booksDeveloping Solutions with SQL Server Developing Solutions with SQL Server 20052005
Professional MOM 2005, SMS 2003, and Professional MOM 2005, SMS 2003, and Microsoft Update Microsoft Update
SQL Server and CLR – Key benefitsSQL Server and CLR – Key benefits
Rich choice of modern languages Rich choice of modern languages VB, C#, Managed C++, COBOL, … VB, C#, Managed C++, COBOL, …
T-SQL continues as a 1T-SQL continues as a 1stst class citizen class citizen
Leverage extensive frameworksLeverage extensive frameworks.NET framework: Use extensive libraries built by .NET framework: Use extensive libraries built by MicrosoftMicrosoft
Enable 3Enable 3rdrd parties to write libraries & extend DB parties to write libraries & extend DB
Leverage extensive tools support for .NETLeverage extensive tools support for .NETVS.NET, Borland & 3VS.NET, Borland & 3rdrd party tools (e.g. profilers) party tools (e.g. profilers)
SQL Server Management StudioSQL Server Management Studio
No more need for XPs!No more need for XPs!
Developer and DBA ConvergenceDeveloper and DBA Convergence
Developers and DBAs have traditionally Developers and DBAs have traditionally worked to an interface, defined by:worked to an interface, defined by:
Table or View definitionTable or View definitionStored Procedure & result set definitionStored Procedure & result set definition
Always carefully plan major technology introductionAlways carefully plan major technology introduction
New features should be “off by default” until their New features should be “off by default” until their utility is understoodutility is understood
Avoid using a feature because it’s there:Avoid using a feature because it’s there:Does it enable us to tackle new business problems?Does it enable us to tackle new business problems?
What impact does it have on support/security?What impact does it have on support/security?
Does it work with your availability plans?Does it work with your availability plans?
Is there a more performant option?Is there a more performant option?
Does it match my IT groups skills – which teams?Does it match my IT groups skills – which teams?
Does it require client/middle-tier server middleware Does it require client/middle-tier server middleware change?change?
Develop clear criteria for usageDevelop clear criteria for usage
Decide which rules also apply to third-party Decide which rules also apply to third-party applicationsapplications
CLR DevelopmentCLR Development
Code & BuildCode & Build DeployDeploy
Module is loaded into SQL ServerModule is loaded into SQL Server Portable & integrated with SQL Portable & integrated with SQL No “lost” code No “lost” code File not needed after “load” File not needed after “load”
Even in supported assemblies, some APIs Even in supported assemblies, some APIs are not available in SQLare not available in SQL
Environment.Exit(), Console, Drawing, etc.Environment.Exit(), Console, Drawing, etc.Full list will be available in documentationFull list will be available in documentation
Achieved through a new “HostProtection” Achieved through a new “HostProtection” attribute in CLRattribute in CLR
Extensible by 3Extensible by 3rdrd party libraries party librariesCan reflect on an assembly and list HPA’ed Can reflect on an assembly and list HPA’ed methodsmethods
Potentially unreliable constructs disabled Potentially unreliable constructs disabled No thread creationNo thread creationNo shared state or synchronizationNo shared state or synchronizationNo listening on sockets in serverNo listening on sockets in server
Checked by SQL during create assembly Checked by SQL during create assembly through a “verification” processthrough a “verification” process
Put computation closer to data Put computation closer to data where where applicableapplicable
Moving computation to where the data Moving computation to where the data is a double edged swordis a double edged sword
Data shipping cost goes awayData shipping cost goes away
Server CPU now used for user processingServer CPU now used for user processing
Code portability: no free lunchCode portability: no free lunchAvoid cosmetic differences, use factory Avoid cosmetic differences, use factory pattern for data accesspattern for data access
SQLCLR is not about moving code SQLCLR is not about moving code from mid-tier to DBfrom mid-tier to DB
Make judicious use of server CPUMake judicious use of server CPU
Not ISAM storeNot ISAM storeLeverage set oriented processingLeverage set oriented processing
SQLCLR is about making your day-to-SQLCLR is about making your day-to-day day DB programmingDB programming easier.. easier..
SQLCLR & CASSQLCLR & CAS
SqlClr Uses CAS to control managed SqlClr Uses CAS to control managed code executioncode executionThree CAS permission bucketsThree CAS permission buckets
SafeSafecompute, access local datacompute, access local data
Leveraging the power of the Microsoft .NET FrameworkLeveraging the power of the Microsoft .NET FrameworkAccess to a rich set of pre-built functionalityAccess to a rich set of pre-built functionality
Replacing Extended Stored Procedures Replacing Extended Stored Procedures (Microsoft Windows XP)(Microsoft Windows XP)
The CLR is safer: The CLR is safer: No access violations making SQL Server crash No access violations making SQL Server crash
No leaks making SQL Server slow down & crashNo leaks making SQL Server slow down & crash
Bad Scenario for CLR UsageBad Scenario for CLR Usage
Heavy data access – Transact-SQL set-based access Heavy data access – Transact-SQL set-based access will be fasterwill be faster
Don’t write SELECT statements as CLR procedures!Don’t write SELECT statements as CLR procedures!
Complex typesComplex types8 K size limitation8 K size limitation
All data is read/re-written when updatedAll data is read/re-written when updated
Pre-Aggregation for ReportsPre-Aggregation for ReportsCLR Aggregates cannot be used in Indexed ViewsCLR Aggregates cannot be used in Indexed Views
Your application must support previous versions of Your application must support previous versions of SQL ServerSQL Server
Technology for technology’s sake…Technology for technology’s sake…
TroubleshootingTroubleshooting
With new tools comes new problemsWith new tools comes new problems
The core engine management tools The core engine management tools now provide greatly enhanced now provide greatly enhanced information about “what is going on”information about “what is going on”
Debugger support for T-SQL & CLRDebugger support for T-SQL & CLR
Dynamic management views for SqlClrDynamic management views for SqlClr