[MS-SSCLRT]: Microsoft SQL Server CLR Types Serialization ...
SQL Server 2005 and the CLR: What do you need to know?
-
Upload
databaseguys -
Category
Documents
-
view
458 -
download
0
Transcript of 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
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
UIUIDevelopmentDevelopment
Web ServiceWeb ServiceDevelopmentDevelopment
DatabaseDatabaseDevelopmentDevelopment
Client/ServerClient/ServerDevelopmentDevelopment
DatabaseDatabaseDevelopmentDevelopment
CLR Development- Procedures- Functions- Triggers- Types- Aggregates
XML Development
InterfaceInterface
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
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!
IT Manager DilemmaIT Manager Dilemma
T-SQL
XML
CLR
Computation Computation & Framework & Framework
accessaccess
Relational Relational data accessdata access
Semi-structuredSemi-structureddata accessdata access
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
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”
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
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
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
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
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..
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
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…
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
Third-party management toolsThird-party management tools
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
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.