WEB325 Building Data-Driven Web Sites in ASP.NET 2.0 Rob Howard [email protected] Telligent...
-
Upload
esther-moody -
Category
Documents
-
view
213 -
download
0
Transcript of WEB325 Building Data-Driven Web Sites in ASP.NET 2.0 Rob Howard [email protected] Telligent...
WEB325WEB325Building Data-Driven Web Sites in Building Data-Driven Web Sites in ASP.NET 2.0ASP.NET 2.0
Rob HowardRob [email protected]@telligent.comTelligent CorporationTelligent Corporation
Contact and SlidesContact and Slides
Rob HowardRob [email protected]@telligent.com
www.telligent.comwww.telligent.com
TelligentTelligent.NET Software Development Company.NET Software Development Company
Builds Community Server (communityserver.org)Builds Community Server (communityserver.org)
Download Slides & DemosDownload Slides & Demoswww.rob-howard.netwww.rob-howard.net
Will be posted ASAPWill be posted ASAP
Review: ASP.NET 1.XReview: ASP.NET 1.X
ASP.NET 1.XASP.NET 1.XIntroduced data controlsIntroduced data controls
Introduced data binding conceptsIntroduced data binding concepts
Working with data in ASP.NET 1.XWorking with data in ASP.NET 1.XEasy and simpleEasy and simple
Too much code still required thoughToo much code still required though
ASP.NET 2.0ASP.NET 2.0Specifically addresses common scenariosSpecifically addresses common scenarios
Makes working with data even easierMakes working with data even easier
AgendaAgenda
Safer connection string storageSafer connection string storage
Data binding gets easierData binding gets easier
Declarative data bindingDeclarative data binding
Working with the new data controlsWorking with the new data controls
Caching dataCaching data
Connection String StorageConnection String Storage
Persistence and declarative referencingPersistence and declarative referencingStored in *.configStored in *.configAvoid hard-coding within pages/codeAvoid hard-coding within pages/codeCan be optionally encryptedCan be optionally encrypted
Built-in design time supportBuilt-in design time supportPromote use for best practicesPromote use for best practicesEnable optional encrypting of values in configEnable optional encrypting of values in config
Admin SupportAdmin SupportMMC Admin Tool SupportMMC Admin Tool SupportConfiguration API SupportConfiguration API Support
Config Connection StringsConfig Connection Strings
<connectionStrings><connectionStrings>
<add name="pubs“ ProviderName=“…”<add name="pubs“ ProviderName=“…”
connectionString=“…” />connectionString=“…” />
</connectionStrings></connectionStrings>
<asp:SqlDataSource Id=“MySource” <asp:SqlDataSource Id=“MySource” ConnectionString=“<%$ connectionStrings:pubs %>” ConnectionString=“<%$ connectionStrings:pubs %>” SelectCommand=“select au_id from authors” SelectCommand=“select au_id from authors” runat=“server”/> runat=“server”/>
Web.config:
Page.aspx:
Dim connstr As String = Dim connstr As String = ConfigurationSettings.ConnectionStrings(“pubs”) ConfigurationSettings.ConnectionStrings(“pubs”)
Code.vb:
Connection StringsConnection Strings
Data Binding Gets EasierData Binding Gets Easier
Expressions are cleanerExpressions are cleaner
Support hierarchical (XML) data Support hierarchical (XML) data bindingbinding
<!-- ASP.NET 1.x data binding expression --><!-- ASP.NET 1.x data binding expression -->
<%# DataBinder.Eval (Container.DataItem, "Price") %><%# DataBinder.Eval (Container.DataItem, "Price") %>
<!-- Equivalent ASP.NET 2.0 data binding expression --><!-- Equivalent ASP.NET 2.0 data binding expression -->
<%# Eval ("Price") %><%# Eval ("Price") %>
<!-- XML data binding --><!-- XML data binding -->
<%# XPath ("Price") %><%# XPath ("Price") %>
Declarative Data BindingDeclarative Data Binding
Controls bound at appropriate timeControls bound at appropriate time
Wire-up done through propertiesWire-up done through properties
Page lifecycle knowledge not requiredPage lifecycle knowledge not required
NameName DescriptionDescription
SqlDataSource Connects data-binding controls to SQL databases
AccessDataSource Connects data-binding controls to Access databases
XmlDataSource Connects data-binding controls to XML data
ObjectDataSource Connects data-binding controls to data components
SiteMapDataSource Connects site navigation controls to site map data
SqlDataSourceSqlDataSource
Data binding to SQL DatabaseData binding to SQL DatabaseMicrosoft SQL Server, Oracle, DB2, etc.Microsoft SQL Server, Oracle, DB2, etc.
Two-way data binding supportedTwo-way data binding supportedSelectCommandSelectCommand
InsertCommand, UpdateCommand, and InsertCommand, UpdateCommand, and DeleteCommandDeleteCommand
Optional caching of query resultsOptional caching of query results
Parameterized operationParameterized operation
Using SqlDataSourceUsing SqlDataSource
<asp:SqlDataSource <asp:SqlDataSource
ID="Titles" ID="Titles" ConnectionString="<%$ connectionStrings:pubs %>" ConnectionString="<%$ connectionStrings:pubs %>" RunAt="server“ RunAt="server“ SelectCommand="select title_id, title, price SelectCommand="select title_id, title, price from titles" from titles" />/>
<asp:DataGrid <asp:DataGrid
DataSourceID="Titles" DataSourceID="Titles"
RunAt="server" />RunAt="server" />
SqlDataSource PropertiesSqlDataSource Properties
NameName DescriptionDescription
ConnectionString Connection string used to connect to data source
SelectCommand Command used to perform queries
InsertCommand Command used to perform inserts
UpdateCommand Command used to perform updates
DeleteCommand Command used to perform deletes
DataSourceMode Specifies whether DataSet or DataReader is used(default = DataSet)
ProviderName Specifies provider (default = SQL Server .NET provider)
SQL Data BindingSQL Data Binding
SqlDataSource and CachingSqlDataSource and Caching
Support declarative cachingSupport declarative caching
NameName DescriptionDescription
EnableCaching Specifies whether caching is enabled (default = false)
CacheDuration Length of time in seconds results should be cached
CacheExpirationPolicy Specifies whether cache duration is sliding or absolute
CacheKeyDependency Creates dependency on specified cache key
SqlCacheDependency Creates dependency on specified database entity
<asp:SqlDataSource <asp:SqlDataSource
ID="Countries" ID="Countries"
RunAt="server"RunAt="server"
SelectCommand="select ..."SelectCommand="select ..."
EnableCaching="true" CacheDuration="60" />EnableCaching="true" CacheDuration="60" />
<asp:DropDownList <asp:DropDownList
ID="MyDropDownList" ID="MyDropDownList"
DataSourceID="Countries“DataSourceID="Countries“
DataTextField="country" DataTextField="country"
AutoPostBack="true" AutoPostBack="true"
RunAt="server" />RunAt="server" />
Caching Query ResultsCaching Query Results
Parameterized CommandsParameterized Commands
Parameter properties Parameter properties Parameterized database commandsParameterized database commands
Example: Example: Get value for WHERE clause in SelectCommand Get value for WHERE clause in SelectCommand from query string parameter or item selected in from query string parameter or item selected in drop-down listdrop-down list
Example: Example: Get value for WHERE clause in DeleteCommand Get value for WHERE clause in DeleteCommand from GridViewfrom GridView
Parameters PropertiesParameters Properties
NameName DescriptionDescription
SelectParameters Specifies parameters for SelectCommand
InsertParameters
UpdateParameters
DeleteParameters
FilterParameters Specifies parameters for FilterExpression
Specifies parameters for InsertCommand
Specifies parameters for UpdateCommand
Specifies parameters for DeleteCommand
Parameter TypesParameter Types
NameName DescriptionDescription
ControlParameter Binds a replaceable parameter to a control property
CookieParameter Binds a replaceable parameter to a cookie value
FormParameter Binds a replaceable parameter to a form field
ProfileParameter Binds a replaceable parameter to a profile property
QueryStringParameter Binds a replaceable parameter to a query string parameter
Parameter Binds a replaceable parameter to a data field
SessionParameter Binds a replaceable parameter to a session variable
Using ControlParameterUsing ControlParameter
<asp:SqlDataSource <asp:SqlDataSource
ID="Countries" RunAt="server"ID="Countries" RunAt="server"
SelectCommand="select distinct ..." />SelectCommand="select distinct ..." />
<asp:SqlDataSource <asp:SqlDataSource
ID="Customers" RunAt="server"ID="Customers" RunAt="server"
SelectCommand="select * from customers where country=@Country">SelectCommand="select * from customers where country=@Country">
<SelectParameters><SelectParameters>
<asp:ControlParameter Name="Country" <asp:ControlParameter Name="Country"
ControlID="MyDropDownList"ControlID="MyDropDownList"
PropertyName="SelectedValue" />PropertyName="SelectedValue" />
</SelectParameters></SelectParameters>
</asp:SqlDataSource></asp:SqlDataSource>
<asp:DropDownList <asp:DropDownList
ID="MyDropDownList" DataSourceID="Countries"ID="MyDropDownList" DataSourceID="Countries"
DataTextField="country" AutoPostBack="true" RunAt="server" />DataTextField="country" AutoPostBack="true" RunAt="server" />
<asp:DataGrid DataSourceID="Customers" RunAt="server" /><asp:DataGrid DataSourceID="Customers" RunAt="server" />
Calling Stored ProceduresCalling Stored Procedures
<asp:SqlDataSource ID="Countries" RunAt="server"<asp:SqlDataSource ID="Countries" RunAt="server" ConnectionString="server=localhost;database=northwind;..."ConnectionString="server=localhost;database=northwind;..." SelectCommand="SelectCommand="proc_GetCountriesproc_GetCountries" />" /><asp:SqlDataSource ID="Customers" RunAt="server"<asp:SqlDataSource ID="Customers" RunAt="server" ConnectionString="server=localhost;database=northwind;..."ConnectionString="server=localhost;database=northwind;..." SelectCommand="SelectCommand="proc_GetCustomersproc_GetCustomers">"> <SelectParameters><SelectParameters> <asp:ControlParameter Name="Country" ControlID="MyDropDownList"<asp:ControlParameter Name="Country" ControlID="MyDropDownList" PropertyName="SelectedValue" />PropertyName="SelectedValue" /> </SelectParameters></SelectParameters></asp:SqlDataSource></asp:SqlDataSource><asp:DropDownList ID="MyDropDownList" DataSourceID="Countries"<asp:DropDownList ID="MyDropDownList" DataSourceID="Countries" DataTextField="country" AutoPostBack="true" RunAt="server" />DataTextField="country" AutoPostBack="true" RunAt="server" /><asp:DataGrid DataSourceID="Customers" RunAt="server" /><asp:DataGrid DataSourceID="Customers" RunAt="server" />
CREATE PROCEDURE proc_GetCustomersCREATE PROCEDURE proc_GetCustomers@Country nvarchar (32) AS@Country nvarchar (32) AS SELECT * FROM CustomersSELECT * FROM Customers WHERE Country = @CountryWHERE Country = @CountryGOGO
CREATE PROCEDURE proc_GetCustomersCREATE PROCEDURE proc_GetCustomers@Country nvarchar (32) AS@Country nvarchar (32) AS SELECT * FROM CustomersSELECT * FROM Customers WHERE Country = @CountryWHERE Country = @CountryGOGO
CREATE PROCEDURE proc_GetCountries ASCREATE PROCEDURE proc_GetCountries AS SELECT DISTINCT CountrySELECT DISTINCT Country FROM CustomersFROM Customers ORDER BY CountryORDER BY CountryGOGO
CREATE PROCEDURE proc_GetCountries ASCREATE PROCEDURE proc_GetCountries AS SELECT DISTINCT CountrySELECT DISTINCT Country FROM CustomersFROM Customers ORDER BY CountryORDER BY CountryGOGO
SqlDataSourceSqlDataSource
Data Source CapabilitiesData Source Capabilities
Common data operations get easierCommon data operations get easierSorting and pagingSorting and pagingSelecting, updating, inserting, deletingSelecting, updating, inserting, deleting
Page developer Page developer Sets properties to enable operationsSets properties to enable operationsEx., UpdateCommandEx., UpdateCommand
““Smart” data-bound controlsSmart” data-bound controlsUse these capabilities directlyUse these capabilities directlyEx., <asp:GridView>, <asp:DetailsView>Ex., <asp:GridView>, <asp:DetailsView>
Sorting, Paging, UpdatingSorting, Paging, Updating
Data Source PagingData Source Paging
Previous demo does paging in UI layerPrevious demo does paging in UI layerSqlDataSource returns all data rowsSqlDataSource returns all data rows
Performs paging by rendering subset of rowsPerforms paging by rendering subset of rows
Paging supported on data source interfacePaging supported on data source interfaceSelect (int startRowIndex, int maxRows)Select (int startRowIndex, int maxRows)
Requires user-defined procedure or custom code Requires user-defined procedure or custom code
Data-bound controlsData-bound controlsDon’t need to page in the UI layerDon’t need to page in the UI layer
Useful (and required) for large amounts of dataUseful (and required) for large amounts of data
Updates, Inserts, DeletesUpdates, Inserts, Deletes
GridView GridView Extracts values from input controlsExtracts values from input controlsKeys from viewstate (DataKeyNames)Keys from viewstate (DataKeyNames)
Dictionaries passed to data source operationDictionaries passed to data source operationUpdate: Keys, Values, OldValuesUpdate: Keys, Values, OldValuesDelete: Keys, OldValuesDelete: Keys, OldValues
Data source applies parameters to commandData source applies parameters to commandRelies on naming convention for parametersRelies on naming convention for parametersKeys, OldValues formatted with “original_” prefixKeys, OldValues formatted with “original_” prefixOldValuesParameterFormatString defines prefixOldValuesParameterFormatString defines prefix
ProgrammabilityProgrammability
Data source events Data source events Enable custom processingEnable custom processing
Use event to:Use event to:Manipulate command and parametersManipulate command and parameters
Cancel operationsCancel operations
Handle errorsHandle errors
Retrieve return values and output paramsRetrieve return values and output params
Rows affectedRows affected
Data-bound controls expose similar eventsData-bound controls expose similar events
Data Source EventsData Source Events
Sub MySource_Selecting(ByVal sender As Object, Sub MySource_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs) ByVal e As SqlDataSourceCommandEventArgs)
Dim cmd As System.Data.SqlClient.SqlCommand = e.CommandDim cmd As System.Data.SqlClient.SqlCommand = e.Command
cmd.Parameters(“UserId”).Value = User.Identity.Namecmd.Parameters(“UserId”).Value = User.Identity.Name
End SubEnd Sub
<asp:SqlDataSource ID=“MySource” …<asp:SqlDataSource ID=“MySource” … OnSelecting=“MySource_Selecting” OnSelecting=“MySource_Selecting” SelectCommand=“sp_GetUserPreferences” SelectCommand=“sp_GetUserPreferences” runat=“server”/> runat=“server”/>
Page.aspx.vb
Page.aspx
ObjectDataSourceObjectDataSource
Most applications encapsulate data logicMost applications encapsulate data logicBest practice and simplifies maintenanceBest practice and simplifies maintenance
Embedding SQL code is not recommendedEmbedding SQL code is not recommended
ObjectDataSource ObjectDataSource Bind to custom business objectsBind to custom business objects
Visual Studio data componentsVisual Studio data components
Parallels SqlDataSource in object modelParallels SqlDataSource in object model
<asp:ObjectDataSource ID=“MySource” <asp:ObjectDataSource ID=“MySource” TypeName=“CustomersDB” TypeName=“CustomersDB” SelectMethod=“GetCustomersByRegion” SelectMethod=“GetCustomersByRegion” UpdateMethod=“UpdateCustomer” UpdateMethod=“UpdateCustomer” runat=“server”/> runat=“server”/>
Web Page
DataSourceID DataSourceID = = ObjectDataSource1ObjectDataSource1
ObjectDataSourceObjectDataSourceObjectDataSourceObjectDataSource
Northwind Northwind DatabaseDatabase
OrdersComponentOrdersComponent
OrderItemsComponentOrderItemsComponent
CompaniesComponentCompaniesComponent
<asp:ObjectDataSource<asp:ObjectDataSourceIDID = ObjectDataSource1 = ObjectDataSource1TypeName = TypeName = OrdersComponentOrdersComponentSelectMethodSelectMethod = GetOrders = GetOrdersUpdateMethodUpdateMethod = UpdateOrder = UpdateOrderDeleteMethodDeleteMethod = DeleteOrder = DeleteOrder
Returns IEnumerable of Returns IEnumerable of OrdersOrders
• Order.OrderIDOrder.OrderID• Order.OrderNameOrder.OrderName• Order.OrderDateOrder.OrderDate
ObjectDataSourceObjectDataSource
Select method can return Select method can return any Object any Object
IEnumerable listIEnumerable list
Collection or arrayCollection or array
GetProducts() -> ProductCollectionGetProducts() -> ProductCollection
GetProductsDataSet() -> DataSetGetProductsDataSet() -> DataSet
GetProduct (int productId) -> ProductGetProduct (int productId) -> Product
ObjectDataSourceObjectDataSource
Update, Insert, Delete methodsUpdate, Insert, Delete methodsTake individual fields or data item objectTake individual fields or data item object
For automatic updates/inserts/deletesFor automatic updates/inserts/deletesProperty or parameter names must match Property or parameter names must match selected fields for GridView/DetailsViewselected fields for GridView/DetailsView
UpdateProduct (int id, String name, double price)UpdateProduct (int id, String name, double price)
UpdateProduct (Product p) // p.Name, p.Price, etc.UpdateProduct (Product p) // p.Name, p.Price, etc.
DeleteProduct (int id)DeleteProduct (int id)
Key PropertiesKey Properties
NameName DescriptionDescription
TypeName Type name of data component
SelectMethod Method called on data component to perform queries
InsertMethod
UpdateMethod
DeleteMethod
EnableCaching Specifies whether caching is enabled (default = false)
Method called on data component to perform inserts
Method called on data component to perform updates
Method called on data component to perform deletes
Key Properties (cont’d)Key Properties (cont’d)
NameName DescriptionDescription
InsertParameters Specifies parameters for InsertMethod
UpdateParameters Specifies parameters for UpdateMethod
DeleteParameters Specifies parameters for DeleteMethod
SelectParameters Specifies parameters for SelectMethod
CacheDuration Length of time in seconds data should be cached
SqlCacheDependency Creates dependency on specified database entity
Initialization and Clean-UpInitialization and Clean-Up
Data operation methods Data operation methods Can identify static methodsCan identify static methodsCan identify instance methodsCan identify instance methods
If instance methods are used:If instance methods are used:New class instance on each callNew class instance on each callMust have public default constructorMust have public default constructor
ObjectCreated and ObjectDisposing ObjectCreated and ObjectDisposing Events to initialize or clean-upEvents to initialize or clean-up
Using ObjectDataSourceUsing ObjectDataSource
What about DataSets?What about DataSets?
Works for both Web and client applicationsWorks for both Web and client applications
Created from Created from DB schemaDB schemaDynamic SQL Dynamic SQL Stored ProceduresStored Procedures
Exposes methods to “Fill” and “Fetch”Exposes methods to “Fill” and “Fetch”Auto-generated Insert/Update/DeleteAuto-generated Insert/Update/Delete
““A middle tier data access layer for Web and client”A middle tier data access layer for Web and client”
What about DataSets?What about DataSets?
Supports partial classes for custom logicSupports partial classes for custom logic
Built in support for common tasksBuilt in support for common tasksSelect, Update, Insert, DeleteSelect, Update, Insert, DeleteBatch updates, Conflict resolution*Batch updates, Conflict resolution*
Works with Web services and remotingWorks with Web services and remotingDataTable can be standalone DataTable can be standalone (XmlSerializable, ReadXml) (XmlSerializable, ReadXml) Exposes “GetBy” for stateless callsExposes “GetBy” for stateless callsCan be used with custom base classesCan be used with custom base classes
GridView ControlGridView Control
Enhanced DataGrid controlEnhanced DataGrid controlRenders sets of records as HTML tablesRenders sets of records as HTML tables
Built-in sorting, paging, selecting, Built-in sorting, paging, selecting, updating, and deleting supportupdating, and deleting supportSupports rich assortment of field types, Supports rich assortment of field types, including CheckBoxFieldsincluding CheckBoxFields
Declared in <Columns> elementDeclared in <Columns> element
Highly customizable UIHighly customizable UI
GridView ExampleGridView Example
<asp:SqlDataSource <asp:SqlDataSource
ID="Employees" ID="Employees"
RunAt="server"RunAt="server"
SelectCommand="select lastname, .../>SelectCommand="select lastname, .../>
<asp:GridView <asp:GridView
DataSourceID="Employees" DataSourceID="Employees"
Width="100%" Width="100%"
RunAt="server" />RunAt="server" />
Rendered GridViewRendered GridView
GridView Field TypesGridView Field Types
Name Description
BoundField Renders columns of text from fields in data source
ButtonField Renders columns of buttons (push button, image, or link)
CheckBoxField Renders Booleans as check boxes
HyperLinkField Renders columns of hyperlinks
TemplateField Renders columns using HTML templates
CommandField Renders controls for selecting and editing GridView data
ImageField Renders columns of images from URL text
Specifying Field TypesSpecifying Field Types
<asp:SqlDataSource ID="Employees" RunAt="server"<asp:SqlDataSource ID="Employees" RunAt="server"
ConnectionString="server=localhost;database=northwind;..."ConnectionString="server=localhost;database=northwind;..."
SelectCommand="select photo, lastname, firstname, title from SelectCommand="select photo, lastname, firstname, title from employees" />employees" />
<asp:GridView DataSourceID="Employees" Width="100%" <asp:GridView DataSourceID="Employees" Width="100%" RunAt="server"RunAt="server"
AutoGenerateColumns="false" >AutoGenerateColumns="false" >
<Columns><Columns>
<asp:TemplateField HeaderText="Name"><asp:TemplateField HeaderText="Name">
<ItemTemplate><ItemTemplate>
<%# Eval ("firstname") + " " + Eval ("lastname") %><%# Eval ("firstname") + " " + Eval ("lastname") %>
</ItemTemplate></ItemTemplate>
</asp:TemplateField></asp:TemplateField>
<asp:BoundField HeaderText="Title" DataField="title" /><asp:BoundField HeaderText="Title" DataField="title" />
</Columns></Columns>
</asp:GridView></asp:GridView>
Rendered OutputRendered Output
DetailsView ControlDetailsView Control
Renders individual recordsRenders individual recordsPair with GridView for master-detail viewsPair with GridView for master-detail viewsOr use without GridView to display Or use without GridView to display individual recordsindividual records
Built-in paging, inserting, updating, Built-in paging, inserting, updating, deletingdeletingUses same field types as GridViewUses same field types as GridView
Declared in <Fields> elementDeclared in <Fields> element
Highly customizable UIHighly customizable UI
DetailsView ExampleDetailsView Example
<asp:SqlDataSource ID="Employees" RunAt="server"<asp:SqlDataSource ID="Employees" RunAt="server"
ConnectionString="server=localhost;database=northwind;..."ConnectionString="server=localhost;database=northwind;..."
SelectCommand="select employeeid, photo, ... from employees" />SelectCommand="select employeeid, photo, ... from employees" />
<asp:DetailsView DataSourceID="Employees" RunAt="server"<asp:DetailsView DataSourceID="Employees" RunAt="server"
AllowPaging="true" AutoGenerateRows="false"AllowPaging="true" AutoGenerateRows="false"
PagerSettings-Mode="NextPreviousFirstLast">PagerSettings-Mode="NextPreviousFirstLast">
<Fields><Fields>
<asp:BoundField HeaderText="Employee ID" DataField="employeeid" /><asp:BoundField HeaderText="Employee ID" DataField="employeeid" />
<asp:BoundField HeaderText="Date Hired" DataField="hiredate" /><asp:BoundField HeaderText="Date Hired" DataField="hiredate" />
<asp:TemplateField HeaderText="Name"><asp:TemplateField HeaderText="Name">
<ItemTemplate><ItemTemplate>
<%# Eval ("firstname") + " " + Eval ("lastname") %><%# Eval ("firstname") + " " + Eval ("lastname") %>
</ItemTemplate></ItemTemplate>
</asp:TemplateField></asp:TemplateField>
<asp:BoundField HeaderText="Title" DataField="title" /><asp:BoundField HeaderText="Title" DataField="title" />
</Fields></Fields>
</asp:DetailsView></asp:DetailsView>
Rendered OutputRendered Output
Master-DetailMaster-Detail
SQL Cache Invalidation SQL Cache Invalidation
New cache dependency typeNew cache dependency typeEmbodied in SqlCacheDependency classEmbodied in SqlCacheDependency class
Configured through Configured through <sqlCacheDependency> configuration <sqlCacheDependency> configuration sectionsection
Links cached items to database entitiesLinks cached items to database entitiesASP.NET application cacheASP.NET application cache
ASP.NET output cacheASP.NET output cache
Compatible with SQL Server 7, 2000, Compatible with SQL Server 7, 2000, 20052005
Using SqlCacheDependency with the Using SqlCacheDependency with the Application CacheApplication Cache
Cache.Insert ("Products", products,Cache.Insert ("Products", products,
new SqlCacheDependency ("Northwind", "Products");new SqlCacheDependency ("Northwind", "Products");
Database name
Table name
Using SqlCacheDependency with the Using SqlCacheDependency with the Output CacheOutput Cache
<%@ OutputCache Duration="60" VaryByParam="None"<%@ OutputCache Duration="60" VaryByParam="None"
SqlDependency="Northwind:Products" %>SqlDependency="Northwind:Products" %>
Database name
Table name
Using SqlCacheDependency with Using SqlCacheDependency with SqlDataSourceSqlDataSource
<asp:SqlDataSource ID="Countries" RunAt="server"<asp:SqlDataSource ID="Countries" RunAt="server"
ConnectionString="server=localhost;database=northwind;..."ConnectionString="server=localhost;database=northwind;..."
SelectCommand="select distinct country from customers order by country"SelectCommand="select distinct country from customers order by country"
EnableCaching="true" CacheDuration="60000"EnableCaching="true" CacheDuration="60000"
SqlCacheDependency="Northwind:Customers" />
<asp:DropDownList ID="MyDropDownList" DataSourceID="Countries"<asp:DropDownList ID="MyDropDownList" DataSourceID="Countries"
DataTextField="country" AutoPostBack="true" RunAt="server" />DataTextField="country" AutoPostBack="true" RunAt="server" />
Database name
Table name
Cache ConfigurationCache Configuration
<cache><cache>Enable/disable application cacheEnable/disable application cache
Enable/disable item expiration and moreEnable/disable item expiration and more
<outputCache>, <outputCache>, <outputCacheSettings><outputCacheSettings>
Enable/disable output cachingEnable/disable output caching
Enable/disable disk-based persistenceEnable/disable disk-based persistence
Set maximum size per app and moreSet maximum size per app and more
<sqlCacheDependency><sqlCacheDependency>
SQL Cache InvalidationSQL Cache Invalidation
ReviewReview
Simplified data bindingSimplified data binding
Data source controlsData source controls
Data controlsData controlsGridView and DetailsView controlsGridView and DetailsView controls
Editing with GridView and DetailsViewEditing with GridView and DetailsView
CachingCachingSQL Cache Invalidation SQL Cache Invalidation
Cache configurationCache configuration
Your FeedbackYour Feedbackis Important!is Important!Please Fill Out a Survey forPlease Fill Out a Survey forThis Session on CommNetThis Session on CommNet
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.