I am lost. I am getting this error.....
Invalid object name 'Contact'.
Description: An unhandled exception occurred during the
execution of
the current web request. Please review the stack trace for
more
information about the error and where it originated in the
code.
Exception Details: System.Data.SqlClient.SqlException:
Invalid object
name 'Contact'.
Visual Studio 2005 w/ MSSQL 2005
aspx PAGE
<% Page Language="C#" %>
<html>
<head id="Head1" runat="server">
<title>
Output Caching With Sql Cache Dependency
</title>
</head>
<body>
<form id="form1"
runat="server">
Notice that the time stamp does not change until you
edit a
record. <br/><br/>
<asp:GridView ID="GridView3"
runat="server" AllowSorting="True"
AutoGenerateEditButton="true"
AutoGenerateColumns="False"
DataKeyNames="ContactID"
DataSourceID="SqlDataSource3"
EmptyDataText="There are no data records to
display."
AllowPaging="True">
<Columns>
<asp:CommandField
ShowDeleteButton="True"
ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField
DataField="ContactID"
HeaderText="ContactID" ReadOnly="True"
SortExpression="ContactID" />
<asp:CheckBoxField
DataField="NameStyle"
HeaderText="NameStyle"
SortExpression="NameStyle" />
<asp:BoundField
DataField="Title" HeaderText="Title"
SortExpression="Title" />
<asp:BoundField
DataField="FirstName"
HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField
DataField="MiddleName"
HeaderText="MiddleName"
SortExpression="MiddleName" />
<asp:BoundField
DataField="LastName"
HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField
DataField="Suffix" HeaderText="Suffix"
SortExpression="Suffix" />
<asp:BoundField
DataField="EmailAddress"
HeaderText="EmailAddress"
SortExpression="EmailAddress" />
<asp:BoundField
DataField="EmailPromotion"
HeaderText="EmailPromotion"
SortExpression="EmailPromotion" />
<asp:BoundField
DataField="Phone" HeaderText="Phone"
SortExpression="Phone" />
<asp:BoundField
DataField="PasswordHash"
HeaderText="PasswordHash"
SortExpression="PasswordHash" />
<asp:BoundField
DataField="PasswordSalt"
HeaderText="PasswordSalt"
SortExpression="PasswordSalt" />
<asp:BoundField
DataField="rowguid"
HeaderText="rowguid"
SortExpression="rowguid" />
<asp:BoundField
DataField="ModifiedDate"
HeaderText="ModifiedDate"
SortExpression="ModifiedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3"
runat="server"
EnableCaching="true"
CacheDuration="Infinite"
SqlCacheDependency="AdventureWorks:Contact"
SelectCommand="SELECT [ContactID],
[NameStyle], [Title],
[FirstName], [MiddleName], [LastName], [Suffix],
[EmailAddress],
[EmailPromotion], [Phone], [PasswordHash], [PasswordSalt],
[AdditionalContactInfo], [rowguid], [ModifiedDate] FROM
[Contact]"
UpdateCommand="UPDATE [Contact] SET
[NameStyle] =
NameStyle, [Title] = Title, [FirstName] = FirstName, [MiddleName] =
MiddleName, [LastName] = LastName, [Suffix] = Suffix,
[EmailAddress]
= EmailAddress, [EmailPromotion] = EmailPromotion, [Phone] = Phone,
[PasswordHash] = PasswordHash, [PasswordSalt] = PasswordSalt,
[rowguid] = rowguid, [ModifiedDate] = ModifiedDate WHERE
[ContactID]
= ContactID"
ConnectionString="<%$
ConnectionStrings:AdventureWorks %>">
</asp:SqlDataSource>
</form>
</body>
</html>
web.conig
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="AdventureWorks"
connectionString="Data
Source=XXXXXXXXXXXXXXXX2005;Initial
Catalog=AdventureWorks;Integrated
Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<caching>
<sqlCacheDependency enabled="true"
pollTime="1000" >
<databases>
<add name="AdventureWorks"
connectionStringName="AdventureWorks"
/>
</databases>
</sqlCacheDependency>
</caching>
<compilation debug="true"/>
</system.web>
</configuration>
Global.asax
<script RunAt="server" Language="c#"
>
void Application_OnStart(Object sender, EventArgs e)
{
// enable sql cache dependency support in the database if
needed
// this will fail if the account does not have
adminstrator
permissions on the Pubs database
string connectionString =
ConfigurationManager.ConnectionStrings["AdventureWorks&
quot;].ConnectionString;
bool needToInstall = true;
try
{
string[] tables =
SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(con
nectionString);
if (tables != null)
{
foreach(string table in tables)
{
if
(table.ToLower().Equals("Person.Contact"))
needToInstall = false;
}
}
}
catch (Exception ex)
{
needToInstall = true;
}
if (needToInstall)
{
SqlCacheDependencyAdmin.EnableNotifications(connectionString
);
SqlCacheDependencyAdmin.EnableTableForNotifications(connecti
onString,
"Person.Contact");
}
}
</script>
|