为什么找不到连接字符串或为空

时间:2014-08-07 21:52:42

标签: c# asp.net web-config

我的web.config文件是这样的:

 <appSettings>
    ...
    <add key="gvConnString" value="user id = user1; password= pwww333; server= magcian; database= OnB; connection timeout=30" />
    ...
  </appSettings>

在我的.aspx页面中,我使用它:

<asp:SqlDataSource ID="dsPopulateDepartment" runat="server" ConnectionString="<%$ ConnectionStrings:gvConnString %>" SelectCommand="SELECT * FROM HERECOMES"></asp:SqlDataSource>

我收到以下错误:

Exception Details: System.InvalidOperationException: The connection name 'gvConnString' was not found in the applications configuration or the connection string is empty.

1 个答案:

答案 0 :(得分:5)

您将连接字符串放在<appSettings>元素中。它需要在<connectionStrings>元素中 - 它们是不同的。

<connectionStrings>
<add name="gvConnString" connectionString="..."/>
</connectionStrings>