views:

46

answers:

2

I have a database at location xmachina\sqlexpress named News, News has a table NewsTable. How do I tell ASP to look at News database? Is it part of the SelectCommand? Or a webconfig variable?

Right now I get a [SqlException (0x80131904): Invalid object name 'NewsTable'.]

web.config

<add name="NewsTableConnectionString" connectionString="Data Source=XMACHINA\SQLEXPRESS;Integrated Security=True" providerName="System.Data.SqlClient" />

Default.aspx

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
   ConnectionString="<%$ ConnectionStrings:NewsTableConnectionString %>"
       ProviderName="<%$ ConnectionStrings:NewsTableConnectionString.ProviderName %>" 
       SelectCommand="SELECT [NewsHeadline] FROM [NewsTable]">
</asp:SqlDataSource>
+2  A: 

use this in your connection string setting in your web.config

Database=News;

See the following site for in depth details: link text

Jason Irwin
+1  A: 

I needed this "Initial Catalog" attribute

<add name="NewsTableConnectionString" connectionString="Data Source=XMACHINA\SQLEXPRESS;Integrated Security=True;Initial Catalog=News" providerName="System.Data.SqlClient" />
iterationx