在应用程序配置中未找到连接名“ETSCenterConnectionString”或者连接字符串为空

昨天写了一段代码,出现错误:

"在应用程序配置中未找到连接名“ETSCenterConnectionString”或者连接字符串为空。"

提示指出错误出现在下面的代码处:

<asp:SqlDataSource ID="SdsNewsDetail" runat ="server"
        ConnectionString="<%$ ConnectionStrings:ETSCenterConnectionString %>"
        SelectCommand="SELECT *FROM[Lab_News] WHERE([NewsID]=&NewsID)">
        <SelectParameters >
            <asp:QueryStringParameter Name="NewsID" QueryStringField ="newsid" Type ="Int32" />
        </SelectParameters>
</asp:SqlDataSource>

最后找了半天,需要在web.config文件中添加一段代码,如下

<connectionStrings>
    <add name="ETSCenterConnectionString" connectionString="Data Source=.;Initial Catalog=ETSCenter;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings> 

用于在web.config文件中声明数据库连接,必不可少!

posted on 2012-06-28 10:19  junhunqu  阅读(1174)  评论(0)    收藏  举报

导航