读书人

asp.net2.0开发指南中的缓存示例有关问

发布时间: 2012-02-12 17:16:34 作者: rapoo

asp.net2.0开发指南中的缓存示例问题请教
RT,看到第12章有个示例是做缓存示例的,现在有两个文件1、default.aspx 2、web.config
按书上的第一步先在命令窗口里面输入“aspnet_regsql -S localhost -U sa - P cjy -d pubs -ed -t titles -et”
其中在default.aspx文件中的代码如下
--------------------------------------------
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>
<%@ OutputCache Duration= "10000 " SqlDependency= "pubs:titles " VaryByParam= "none " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<fieldset style= "width:260px; ">
<legend> SQL数据缓存依赖应用 </legend>
<br />
asdf
<asp:GridView ID= "GridView1 " runat= "server " AllowPaging= "True " AutoGenerateColumns= "False "
DataSourceID= "SqlDataSource1 " PageSize= "6 ">
<Columns>
<asp:BoundField HeaderText= "ID号 " DataField= "title_id " ReadOnly= "true " SortExpression= "title_id " />
<asp:BoundField HeaderText= "价格 " DataField= "price " SortExpression= "price " />
<asp:BoundField HeaderText= "Ad " DataField= "advance " SortExpression= "advance " />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID= "SqlDataSource1 " runat= "server " ConnectionString= " <%$ ConnectionStrings:pubsConnectionString %> "
SelectCommand= "SELECT [price], [title_id], [advance] FROM [titles] where [type] = 'business ' "> </asp:SqlDataSource>
<asp:Label ID= "Label1 " runat= "server " Text= " "> </asp:Label> </fieldset>


</div>
</form>
</body>
</html>
--------------------------------------------
2、web.config文件中的代码如下
------------------------------------------
<configuration>
<connectionStrings>
<add name= "PubsString " connectionString= "Data Source=localhost;Initial Catalog=pubs;IntegratedSecurity=True "
providerName= "System.Data.SqlClient " />
<add name= "pubsConnectionString " connectionString= "Data Source=CHENHAN;Initial Catalog=pubs;User ID=sa;Password=cjy "
providerName= "System.Data.SqlClient " />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled= "true " pollTime= "600 ">
<databases>
<add name= "PubsDB " connectionStringName= "PubsString "/>
</databases>
</sqlCacheDependency>
</caching>
</configuration>
------------------------------------------


现在的问题是运行一半时会自动打开default.aspx.cs文件,并提示两个错误,一个是“+$exception{ "OutputCache 指令的“pubs:titles”SqlDependency 属性无效。\r\n\r\n详细错误信息: 无法在配置中找到“pubs”数据库。 "}System.Exception {System.Web.HttpException}”

另一个是“+this{ASP.default_aspx}ASP.default_aspx

-----------------这要如何解决啊。。谢谢


[解决办法]
SqlDependency 需要用工具在sql中注册的。

读书人网 >asp.net

热点推荐