SQL Server 2005 Query Notifications

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Getting Started with Oracle and .NET
Sofia, Bulgaria | 9-10 October Developing An Advanced ASP.NET Server Control With Rich Design-Time Goksin Bakir Yage Ltd Microsoft Regional Director, MEA.
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
The creation of "Yaolan.com" A Site for Pre-natal and Parenting Education in Chinese by James Caldwell DAE Interactive Marketing a Web Connection Company.
17. Data Access ADO.Net Architecture New Features of ADO.NET
1 Migrating from Access to SQL Server Simon Kingston, CSU / NPS NRGIS.
New Release Announcements and Product Roadmap Chris DiPierro, Director of Software Development April 9-11, 2014
Advanced Performance Techniques in ASP.NET 2.0 William Zhang, Ph.D. Senior Consultant Microsoft Consulting Services.
ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.

Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Forms Authentication, Users, Roles, Membership Ventsislav Popov Crossroad Ltd.
ASP.NET Best Practices Dawit Wubshet Park University.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
DEV450 Visual Studio: Best Practices For Debugging Managed Applications Habib Heydarian Scott Nonnenberg Program Managers Microsoft Corporation.
Service Broker Lesson 11. Skills Matrix Service Broker Service Broker, provides a solution to common problems with message delivery and consistency that.
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
Overview What is SQL Server? Creating databases Administration Security Backup.
CNUG Day of.NET: October 30th SQL Server 2005: A Developers Introduction Shawn Wildermuth Magenic Technologies, Inc.
Native Support for Web Services  Native Web services access  Enables cross platform interoperability  Reduces middle-tier dependency (no IIS)  Simplifies.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
Sofia, Bulgaria | 9-10 October Asynchronous Programming for ASP.NET 2.0 Developers Julie Lerman The Data Farm Julie Lerman The Data Farm.
Visual Studio ®.NET Data with XML Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft Modified.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
Sofia, Bulgaria | 9-10 October Concurrency Management – ADO.NET 2.0 Presented By: Sahil Malik Presented By: Sahil Malik
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Tom Castiglia Hershey Technologies
Sofia, Bulgaria | 9-10 October Developing Custom ASP.NET Providers For Membership And Role Manager Goksin Bakir Yage Ltd Microsoft Regional Director, MEA.
Sofia, Bulgaria | 9-10 October Advanced Data Access Patterns with ADO.NET 2.0 Julie Lerman The Data Farm Julie Lerman The Data Farm.
Searching Business Data with MOSS 2007 Enterprise Search Presenter: Corey Roth Enterprise Consultant Stonebridge Blog:
Caching Chapter 12. Caching For high-performance apps Caching: storing frequently-used items in memory –Accessed more quickly Cached Web Form bypasses:
BA372 Stored Procedures and Triggers Lab. What needs to be done to change a customer’s credit limit? Who am I? May I? Do it Log it Display A database.
Sofia, Bulgaria | 9-10 October Troubleshooting Web Site Performance Issues with Visual Studio Team System Martin Kulov Director,.NET Development National.
Windows Forms in Visual Studio 2005 Mike Pelton Systems Engineer Microsoft Ltd
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
DAT356 Hackers Paradise SQL Injection Attacks Doug Seven, Microsoft MVP Cofounder of SqlJunkies.com
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Web Part Development Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Web Part.
DAT 332 SQL Server 2000 Data Transformation Services (DTS) Best Practices Euan Garden Product Unit Manager SQL Server Development Microsoft Corporation.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
The business logic engine for Microsoft IIS Speaker T.M. Arnett.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Stored Procedures / Session 4/ 1 of 41 Session 4 Module 7: Introducing stored procedures Module 8: More about stored procedures.
7-1 Active Server and ADO Colorado Technical University IT420 Tim Peterson.
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
Navigation Framework using CF Architecture for a Client-Server Application using the open standards of the Web presented by Kedar Desai Differential Technologies,
Advanced Database & Client Server Introduction to MS SQL Server 2000 and Transact SQL -
Oracle Query VBA Tool (OQVT)
ASP.net Course From Intermediate to Advance level By Arsalan Ahmed 3 Months Course Cell :
Spaso Lazarević Microsoft MVP Nova banka ad Banja Luka Building business application using Visual Studio 2013 LightSwitch.
Developing Custom ASP.NET Providers For Membership And Role Manager Stefan Schackow PRS404 Program Manager – Web Platform and Tools Microsoft Corporation.
© SCRIBE SOFTWARE CORPORATION 2008 Tips and Tricks for Working with Scribe Insight Trace Files.
.NET Data Access and Manipulation
Generating XML Data from a Database Eugenia Fernandez IUPUI.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
FileTables Sam Nasr, MCAD, MCTS, MVP NIS Technologies
ASP.NET Programming with C# and SQL Server First Edition
SQL Server Security & Intrusion Prevention
Explore the Integration Services Catalog
Effective T-SQL Solutions
# 66.
Integrating Enterprise Applications Into SharePoint® Portal Server
Netscape Application Server
FileTables By Sam Nasr, MCAD, MCT, MCTS NIS October 6, 2012
Using FileTables Sam Nasr, MCAD, MCTS, MVP NIS Technologies
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Chapter 10 ADO.
Presentation transcript:

SQL Server 2005 Query Notifications in ASP.NET 2.0 & ADO.NET 2.0 Julie Lerman The Data Farm

About Me Independent Software Developer 20+ years development experience Microsoft .NET MVP ASPInsider INETA Speaker Various publications & conferences Blogs: thedatafarm.com/blog blog.ziffdavis.com/devlife Founder and leader of Vermont .NET Vermont Software Developer Alliance Board

Agenda SQL Server 2005 Query Notifications ADO.NET 2.0 Notifications ASP.NET 2.0 Cache Invalidation

Query Notifications New feature in SQL Server 2005 Works with SQL Server Service Broker Enables asynchronous database apps Uses queues as first class objects T-SQL can interact with the queues Transactional Message Processing Reliable Distributed Processing *Not* Notification Services

How they work SQL Server Query from Client Data Notification Flag Change Detection for rowset DML SQL Server Service Broker Message Queue Services Listener Application SQL Server 2005

Uses Queries that do not change frequently Queries that need to stick around for a while Look-up Tables When details of change are unimportant Only reports that “something has changed” Web Applications Page level or middle tier Windows Apps Server tier (e.g. remoting or web services) Client side: no more than 10 concurrent users

Query Rules Use explicit columns in command text Required for Change Detection internals “select *” will not work Use two-part names to reference tables e.g.: owner.tablename or schema.tablename NO! UNION, Outer Joins, TOP, DISTINCT, COUNT*, aggregates (AVG, MAX, etc.), INTO, more... (see resources for list) TEMP, table variables, multiple views, system tables/views, queues, more....

ALTER DATABASE mydb SET ENABLE_BROKER SQL Server Rules Enable Service Broker on database SQL Server security has this off by default ALTER DATABASE mydb SET ENABLE_BROKER Database Compatibility Level = 90 Older databases (e.g. pubs) might be 80 or lower sp_dbcmptlevel or Database/Properties/Options Permissions for non-admins One time setup per account

Non-Admin setup TSQL sql_dependencey_subscriber role in SQL Server EXEC sp_addrole 'sql_dependency_subscriber’ Permissions needed for users to Start GRANT CREATE PROCEDURE to startUser GRANT CREATE QUEUE to startUser GRANT CREATE SERVICE to startUser GRANT REFERENCES on CONTRACT:: [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to startUser GRANT VIEW DEFINITION TO startUser Permissions needed for users to Execute GRANT SELECT to executeUser GRANT SUBSCRIBE QUERY NOTIFICATIONS TO executeUser GRANT RECEIVE ON QueryNotificationErrorsQueue TO executeUser GRANT REFERENCES on CONTRACT:: [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to executeUser EXEC sp_addrolemember 'sql_dependency_subscriber', 'executeUser' *Sushil Chordia on blogs.msdn.com/dataworks

ADO.NET 2.0 Integration SqlDependency class [System.Data.SqlClient namespace] Uses SqlQueryNotificationService in MSDB database SqlNotificationRequest class [System.Data.Sql namespace] Requires you to write your own listener Works with DataReaders & DataAdapters

SQLDependency: Basic Functionality Demonstration SQLDependency: Basic Functionality

SqlDependency Steps SqlDependency.Start(Connection) Create SqlCommand Only needed once per app e.g. in Global.ASAX Create SqlCommand Create SqlDependency Attach SqlDependency to SqlCommand Execute SqlCommand Create delegate to listen for OnChange and/or SqlDependency.Changed property

The Plumbing Data Change SqlDep Start SQL Connection Service Broker creates queue creates service creates sproc for cleanup “something changed!” Data Container Query w/ Depend Application SQL Server 2005

SqlDependency.Start Creates static non-pooled connection Creates default queues and services Optional Create your own custom services & queues in SQL Server and pass the queue name as a parameter with Start SqlDependency.Start(connString) or SqlDependency.Start(connString,”myQueue”,”myService”)

SqlNotificationEventArgs Notification is not always about a change Type Source Info One of 18 Enums can be returned Update Invalid: Query does not follow rules Options: Not all SQL Server options are set more… Notification returns immediately for problems

In the Middle Tier Cache Data at the Application Level All client sessions get data from that cache Notification triggers the cache to update

SqlDependency in the Middle Tier Demonstration SqlDependency in the Middle Tier

SqlNotificationRequest Lower level than SqlDependency Does not use default queue in SQL Server Custom Service and Queue must be created in SQL Server in advance Does not require an application wide “Start” Definitely for the middle tier

SqlNotificationRequest Steps Create QUEUE & SERVICE in SS2005 Create SqlCommand Create SqlNotificationRequest Point request to QUEUE & SERVICE Attach SqlNotificationRequest to SqlCommand Execute SqlCommand Run WAITFOR Query Handle results of WAITFOR

Create Queue & Service CREATE QUEUE myqueue CREATE SERVICE myservice ON QUEUE myqueue ([http://schemas.microsoft.com/SQL/Notifications/ PostQueryNotification])

SqlNotificationRequest Demonstration SqlNotificationRequest

Cache Invalidation 1.x Invalidate triggers with: File Change Key Change (pointing to different cache) Time Based Database change invalidation Complicated trickery Can be done with bells and whistles involving SQL Server TRIGGERS and file dependency re Jeff Prosise Wicked Code http://msdn.microsoft.com/msdnmag/issues/03/04/WickedCode/default.aspx for doing this in 1.x

Cache Invalidation 2.0 SqlCacheDependency class System.Web.Caching namespace Inherits from System.Web.Caching.CacheDependency Internals similar to SqlDependency Plugs into the Output Cache Two methods Server-side code using SqlCacheDependency Client side within <% OutputCache > directive

Demonstration SqlCacheDependency

SqlCacheDependency Steps Similar to SqlDependency SqlDependency.Start Create SqlCommand Create SqlCacheDependency Attach SqlCacheDependency to command Execute Command Add SqlCacheDependency to the Cache of the Response object Set Cache properties

<% OutputCache…> Remember the SqlDependency.Start Can be in global.asax System.Data.SqlClient.SqlDependency.Start(ConfigurationManager.ConnectionStrings[“myConn”].ConnectionString) SqlDependency=“CommandNotification” Flags ASP.NET to use SQL Server 2005 Query Notification Applies to all valid queries related to page SqlDependency= anything else Will use polling method to check for changes to database Requires additional setup in web.config & aspnet_regsql.exe command line tool Works with SS2005, SS2000, SS7 for pre-sql2005: <caching>             <sqlCacheDependency>                         <databases>                                     <add name=”Northwind” connectionStringName=”NorthwindConnectionString1” />                         </databases>             </sqlCacheDependency> </caching> And then enable the database and table for notification: Aspnet_regsql.exe –S <server> -U <user> -P <password> -ed –d Northwind –et –t Products

<% OutputCache…> Demonstration <% OutputCache…>

Conclusion Query Notification is a powerful feature for ASP.NET Applications Best target is read-mostly lookup tables Use in middle with ADO.NET classes Use at page level with ASP.NET classes

Contact Info Julie Lerman jlerman@thedatafarm.com www.thedatafarm.com www.thedatafarm.com/blog

Resources Query Notifications in ADO.NET 2.0 Bob Beauchemin, MSDN Online April 2005 What’s New in ADO.NET 2.0 Julia Lerman, MSDN Magazine April 2005 Caching Improvements in ASP.NET Whidbey G. Andrew Duthie, MSDN Online Feb 2004 Improved Caching in ASP.NET 2.0 Stephen Walther, MSDN Online, June 2004 Asynchronous Command Execution in ADO.NET 2.0 Pablo Castro, MSDN Online, July 2004 ADO.NET 2.0 and System.Xml v.2.0 – The Beta Version Alex Homer, Dave Sussman, Mark Fussell Addison-Wesley, April 2005

Please fill out the survey forms Please fill out the survey forms! They are the key to amazing prizes that you can get at the end of each day Thank you!