SQL Server 2005 and the CLR: What do you need to know?
Upcoming SlideShare
Loading in...5

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






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 08/11/10 12:06

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

  • SQL Server 2005 and the CLR: What do you need to know? Randy Holloway Solution Specialist- App Plat & Dev Microsoft Corporation
  • Speaker – Randy Holloway
    • Former IT Director and Software Development Manager
    • Author of over thirty articles on .NET, SQL Server and other Microsoft technologies
    • Author of two upcoming books
      • Developing Solutions with SQL Server 2005
      • Professional MOM 2005, SMS 2003, and Microsoft Update
  • SQL Server and CLR – Key benefits
    • Rich choice of modern languages
      • VB, C#, Managed C++, COBOL, …
      • T-SQL continues as a 1 st class citizen
    • Leverage extensive frameworks
      • .NET framework: Use extensive libraries built by Microsoft
      • Enable 3 rd parties to write libraries & extend DB
    • Leverage extensive tools support for .NET
      • VS.NET, Borland & 3 rd party tools (e.g. profilers)
      • SQL Server Management Studio
    • No more need for XPs!
  • Developer and DBA Convergence
    • Developers and DBAs have traditionally worked to an interface, defined by:
      • Table or View definition
      • Stored Procedure & result set definition
    UI Development Web Service Development Database Development Client/Server Development Database Development CLR Development - Procedures - Functions - Triggers - Types - Aggregates XML Development Interface
  • Communication Barriers
    • Pockets of information within disciplines
    • Unclear delineation of responsibilities
    • Conflicting best practices and architectures
    • Conflicting strategic goals and objectives
    Database Architect Solution Architect Database Administration doesn’t understand our development priorities Development doesn’t understand good query design Reduce complexity through clear release management processes Increase communication and collaboration via product integration
  • Developer and DBA Convergence
    • Developers:
      • Get productive with the new tools
      • Closer integration of DBAs into the development process
      • Design application to be:
        • Supportable
        • Resilient to change
      • Ensure secure, robust implementation
    • DBAs:
      • Maintain role as data steward
      • Understand & advise on appropriate technology choices
      • Factor XML & CLR into schema design
      • Ensure secure, robust implementation
    Bridge the gap!
  • IT Manager Dilemma T-SQL XML CLR Computation & Framework access Relational data access Semi-structured data access
  • Coping With the Dilemma
    • Always carefully plan major technology introduction
    • New features should be “off by default” until their utility is understood
    • Avoid using a feature because it’s there:
      • Does it enable us to tackle new business problems?
      • What impact does it have on support/security?
      • Does it work with your availability plans?
      • Is there a more performant option?
      • Does it match my IT groups skills – which teams?
      • Does it require client/middle-tier server middleware change?
      •  Develop clear criteria for usage
    • Decide which rules also apply to third-party applications
  • CLR Development Code & Build Deploy Module is loaded into SQL Server  Portable & integrated with SQL  No “lost” code  File not needed after “load”
  • Deep CLR Integration
    • Hosting layer provides coordination of:
      • Assembly Loading
      • Memory management
      • Security Model
      • Reliability
      • Threads & Fibers
      • Deadlock detection
      • Execution context
    SQL Engine Windows SQL OS CLR Hosting Layer
  • Feature Overview X Aggregates X User-Defined Types X X Triggers X X Stored Procedures X X User Defined Functions .NET Languages T-SQL
  • Walled garden in DB
    • Even in supported assemblies, some APIs are not available in SQL
      • Environment.Exit(), Console, Drawing, etc.
      • Full list will be available in documentation
    • Achieved through a new “HostProtection” attribute in CLR
      • Extensible by 3 rd party libraries
      • Can reflect on an assembly and list HPA’ed methods
    • Potentially unreliable constructs disabled
      • No thread creation
      • No shared state or synchronization
      • No listening on sockets in server
    • Checked by SQL during create assembly through a “verification” process
  • Put computation closer to data where applicable
    • Moving computation to where the data is a double edged sword
      • Data shipping cost goes away
      • Server CPU now used for user processing
    • Code portability: no free lunch
      • Avoid cosmetic differences, use factory pattern for data access
      • Writing tier agnostic code takes upfront design
  • Devs: Uses & misuses
    • SQLCLR is not about moving code from mid-tier to DB
    • Make judicious use of server CPU
    • Not ISAM store
      • Leverage set oriented processing
      • SQLCLR is about making your day-to-day DB programming easier..
  • Code Access Security (CAS) refresher
    • Assign “permissions” to assemblies based on “evidence”
    • Permission is authorization to perform protected operations
      • E.g. access to OS resources
    • Evidence is metadata associated with assembly
      • E.g. location, creator, etc.
    • SqlClr Uses CAS to control managed code execution
    • Three CAS permission buckets
      • Safe
        • compute, access local data
      • external access
        • files, registry, network
      • Unsafe
        • full trust, unmanaged code, verification
    • Bucket determined at create time
      • create assembly foo from ‘c:foo.dll’
      • with permission_set = safe
  • Good Scenario for CLR Usage
    • Data validation & network traffic reduction
    • Writing general purpose functions:
      • Data passed as arguments
      • Little/no additional data access
      • Complex computation applied on a row-by-row basis to the data
    • Scalar types & custom aggregations
    • Leveraging the power of the Microsoft .NET Framework
      • Access to a rich set of pre-built functionality
    • Replacing Extended Stored Procedures (Microsoft Windows XP)
      • The CLR is safer:
        • No access violations making SQL Server crash
        • No leaks making SQL Server slow down & crash
        • Better performance & scalability (managed memory model)
        • No security issues…
  • Bad Scenario for CLR Usage
    • Heavy data access – Transact-SQL set-based access will be faster
      • Don’t write SELECT statements as CLR procedures!
    • Complex types
      • 8 K size limitation
      • All data is read/re-written when updated
    • Pre-Aggregation for Reports
      • CLR Aggregates cannot be used in Indexed Views
    • Your application must support previous versions of SQL Server
    • Technology for technology’s sake…
  • Troubleshooting
    • With new tools comes new problems
    • The core engine management tools now provide greatly enhanced information about “what is going on”
      • Debugger support for T-SQL & CLR
      • Dynamic management views for SqlClr
      • Third-party management tools
  • Resources More about Microsoft Visual Studio 2005: http://lab.msdn.microsoft.com/vs2005/ 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 for 25+ 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.