SQL Server 2005 and the CLR: What do you need to know?

20
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

Transcript of SQL Server 2005 and the CLR: What do you need to know?

Page 1: SQL Server 2005 and the CLR: What do you need to know?

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

Page 2: SQL Server 2005 and the CLR: What do you need to know?

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

Page 3: SQL Server 2005 and the CLR: What do you need to know?

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!

Page 4: SQL Server 2005 and the CLR: What do you need to know?

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

UIUIDevelopmentDevelopment

Web ServiceWeb ServiceDevelopmentDevelopment

DatabaseDatabaseDevelopmentDevelopment

Client/ServerClient/ServerDevelopmentDevelopment

DatabaseDatabaseDevelopmentDevelopment

CLR Development- Procedures- Functions- Triggers- Types- Aggregates

XML Development

InterfaceInterface

Page 5: SQL Server 2005 and the CLR: What do you need to know?

Communication BarriersCommunication Barriers

Pockets of information within disciplinesPockets of information within disciplines

Unclear delineation of responsibilitiesUnclear delineation of responsibilities

Conflicting best practices and architecturesConflicting best practices and architectures

Conflicting strategic goals and objectivesConflicting strategic goals and objectives

DatabaseDatabaseArchitectArchitectSolutionSolution

ArchitectArchitect

Database Administrationdoesn’t understand our development priorities

Development doesn’tunderstand good querydesign

Reduce complexityReduce complexitythrough clear releasethrough clear releasemanagement processesmanagement processes

Increase communication Increase communication and collaborationand collaboration

via product integrationvia product integration

Jessica McCaffree
HT: Tahoma?
Page 6: SQL Server 2005 and the CLR: What do you need to know?

Developer and DBA ConvergenceDeveloper and DBA Convergence

Developers:Developers:Get productive with the Get productive with the new toolsnew tools

Closer integration of DBAs Closer integration of DBAs into the development into the development processprocess

Design application to be:Design application to be:SupportableSupportable

Resilient to changeResilient to change

Ensure secure, robust Ensure secure, robust implementationimplementation

DBAs:DBAs:Maintain role as data Maintain role as data stewardsteward

Understand & advise on Understand & advise on appropriate technology appropriate technology choiceschoices

Factor XML & CLR into Factor XML & CLR into schema designschema design

Ensure secure, robust Ensure secure, robust implementationimplementation

Bridge the gap!Bridge the gap!

Page 7: SQL Server 2005 and the CLR: What do you need to know?

IT Manager DilemmaIT Manager Dilemma

T-SQL

XML

CLR

Computation Computation & Framework & Framework

accessaccess

Relational Relational data accessdata access

Semi-structuredSemi-structureddata accessdata access

Page 8: SQL Server 2005 and the CLR: What do you need to know?

Coping With the DilemmaCoping With the Dilemma

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

Page 9: SQL Server 2005 and the CLR: What do you need to know?

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”

Page 10: SQL Server 2005 and the CLR: What do you need to know?

Deep CLR IntegrationDeep CLR Integration

Hosting layer provides Hosting layer provides coordination of:coordination of:

Assembly LoadingAssembly Loading

Memory managementMemory management

Security ModelSecurity Model

ReliabilityReliability

Threads & FibersThreads & Fibers

Deadlock detectionDeadlock detection

Execution contextExecution context

SQL EngineSQL Engine

WindowsWindows

SQL OSSQL OS

CLRCLR

HostingHostingLayerLayer

Page 11: SQL Server 2005 and the CLR: What do you need to know?

Feature OverviewFeature Overview

T-SQL .NET Languages

User Defined Functions

X X

Stored Procedures

X X

Triggers X X

User-Defined Types

X

Aggregates X

Page 12: SQL Server 2005 and the CLR: What do you need to know?

Walled garden in DBWalled garden in DB

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

Page 13: SQL Server 2005 and the CLR: What do you need to know?

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

Writing tier agnostic code takes upfront Writing tier agnostic code takes upfront designdesign

Page 14: SQL Server 2005 and the CLR: What do you need to know?

Devs: Uses & misusesDevs: Uses & misuses

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..

Page 15: SQL Server 2005 and the CLR: What do you need to know?

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

external accessexternal accessfiles, registry, networkfiles, registry, network

UnsafeUnsafefull trust, unmanaged code, verificationfull trust, unmanaged code, verification

Bucket determined at create timeBucket determined at create timecreate assembly foo from ‘c:\foo.dll’create assembly foo from ‘c:\foo.dll’with permission_set = safewith permission_set = safe

Page 16: SQL Server 2005 and the CLR: What do you need to know?

Good Scenario for CLR UsageGood Scenario for CLR Usage

Data validation & network traffic reductionData validation & network traffic reduction

Writing general purpose functions:Writing general purpose functions:Data passed as argumentsData passed as arguments

Little/no additional data accessLittle/no additional data access

Complex computation applied on a row-by-row basis to the dataComplex computation applied on a row-by-row basis to the data

Scalar types & custom aggregationsScalar types & custom aggregations

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

Better performance & scalability (managed memory model)Better performance & scalability (managed memory model)

No security issues…No security issues…

Page 17: SQL Server 2005 and the CLR: What do you need to know?

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…

Page 18: SQL Server 2005 and the CLR: What do you need to know?

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

Third-party management toolsThird-party management tools

Page 19: SQL Server 2005 and the CLR: What do you need to know?

ResourcesResources

More about Microsoft Visual Studio 2005: More about Microsoft Visual Studio 2005: http://lab.msdn.microsoft.com/vs2005/

More about Microsoft SQL Server 2005: More about Microsoft SQL Server 2005: http://msdn.microsoft.com/SQL/2005/default.aspx

“SQL Server 2005 Webcasts” contains links to 15 webcasts recorded in December to help get you started

“SQL Server 2005 Articles” contains links for25+ articles/whitepapers on Beta 2

Page 20: SQL Server 2005 and the CLR: What do you need to know?

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.