Unable to connect to SQL database
Hi,
I'm working listings 20-5 and 20-6, and keep getting the following error:
Unable to connect to SQL database 'Northwind' for cache dependency polling
I have run the aspnet_regsql.exe command to enable cacheing for both tables and the database. When I use the -lt option, both tables (Customers and Products) are listed. But when I open the AspNet_SqlCacheTablesForChangeNotification table, it is empty.
Here is my code:
<code>
aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="SqlCacheInvalidation.aspx.cs"Inherits="SqlCacheDependencies"Trace="true" %>
<%@OutputCacheDuration="3600"VaryByParam="none"SqlDependency="Northwind:Customers" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Sql Cache Invalidation</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:LabelID="Label1"runat="server"></asp:Label>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:AppConnectionString1.ProviderNam e %>"SelectCommand="SELECT * FROM [Customers]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
code behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
publicpartialclassSqlCacheDependencies :
System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
Label1.Text = "Page created at " + DateTime.Now.ToShortTimeString();
}
}
web.config
<connectionStrings>
<removename="LocalSqlServer"/>
<addname="LocalSqlServer"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|aspnet.mdf;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/>
<addname="AppConnectionString1"connectionString=
"data source=tommagaro-pc\sqlexpress; database=Northwind; Persist Security info=false"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependencyenabled="true">
<databases>
<addname="Northwind"connectionStringName="AppConnectionString1"
pollTime="500"/>
</databases>
</sqlCacheDependency>
</caching>
</code>
Has anyone else encountered this problem?
The flashman
__________________
Thomas G Magaro
|