SQL Server 2005 and the CLR: What do you need to know? Randy Holloway Solution Specialist- App Plat & Dev Microsoft Corpor...
Speaker – Randy Holloway <ul><li>Former IT Director and Software Development Manager </li></ul><ul><li>Author of over thir...
SQL Server and CLR – Key benefits <ul><li>Rich choice of modern languages  </li></ul><ul><ul><li>VB, C#, Managed C++, COBO...
Developer and DBA Convergence <ul><li>Developers and DBAs have traditionally worked to an interface, defined by: </li></ul...
Communication Barriers <ul><li>Pockets of information within disciplines </li></ul><ul><li>Unclear delineation of responsi...
Developer and DBA Convergence <ul><li>Developers: </li></ul><ul><ul><li>Get productive with the new tools </li></ul></ul><...
IT Manager Dilemma T-SQL XML CLR Computation & Framework access Relational data access Semi-structured data access
Coping With the Dilemma <ul><li>Always carefully plan major technology introduction </li></ul><ul><li>New features should ...
CLR Development Code & Build Deploy Module is loaded into SQL Server   Portable & integrated with SQL   No “lost” code ...
Deep CLR Integration <ul><li>Hosting layer provides coordination of: </li></ul><ul><ul><li>Assembly Loading </li></ul></ul...
Feature Overview X Aggregates X User-Defined Types X X Triggers X X Stored Procedures X X User Defined Functions .NET Lang...
Walled garden in DB <ul><li>Even in supported assemblies, some APIs are not available in SQL </li></ul><ul><ul><li>Environ...
Put computation closer to data  where applicable <ul><li>Moving computation to where the data is a double edged sword </li...
Devs: Uses & misuses <ul><li>SQLCLR is not about moving code from mid-tier to DB </li></ul><ul><li>Make judicious use of s...
Code Access Security (CAS) refresher <ul><li>Assign “permissions” to assemblies based on “evidence” </li></ul><ul><li>Perm...
SQLCLR & CAS <ul><li>SqlClr Uses CAS to control managed code execution </li></ul><ul><li>Three CAS permission buckets </li...
Good Scenario for CLR Usage <ul><li>Data validation & network traffic reduction </li></ul><ul><li>Writing general purpose ...
Bad Scenario for CLR Usage <ul><li>Heavy data access – Transact-SQL set-based access will be faster </li></ul><ul><ul><li>...
Troubleshooting <ul><li>With new tools comes new problems </li></ul><ul><li>The core engine management tools now provide g...
Resources More about Microsoft Visual Studio 2005:  http://lab.msdn.microsoft.com/vs2005/ More about Microsoft SQL Server ...
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes n...
Upcoming SlideShare
Loading in …5
×

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

610 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
610
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • © 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?

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

    ×