如何在ASP.Net中设置数据库
问题描述:
我有一个数据库位于xmachina \ sqlexpress命名为News,News有一个表NewsTable。我如何告诉ASP查看新闻数据库?它是SelectCommand的一部分吗?或者一个webconfig变量?如何在ASP.Net中设置数据库
现在我得到了[SQLEXCEPTION(0x80131904):无效的对象名称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>
答
我需要这个 “初始目录” 属性
<add name="NewsTableConnectionString" connectionString="Data Source=XMACHINA\SQLEXPRESS;Integrated Security=True;Initial Catalog=News" providerName="System.Data.SqlClient" />