我的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.
答案 0 :(得分:5)
您将连接字符串放在<appSettings>
元素中。它需要在<connectionStrings>
元素中 - 它们是不同的。
<connectionStrings>
<add name="gvConnString" connectionString="..."/>
</connectionStrings>