需要帮助(appSetting .aspx文件中的值)RSS

时间:2014-10-20 17:31:18

标签: database-connection appsettings

我将我的web.config配置为sql server数据库

<appSettings>
<add key="OnlineDiscussionSqlCon" value="Data Source=.;Initial Catalog=OnlineDiscussionForum;Integrated Security=True" />

多数工作正常,

但我无法访问.aspx文件中的数据库

我的.aspx文件是

<%@ Page Language="C#" MasterPageFile="~/User/MasterPage.master" AutoEventWireup="true" CodeFile="WelcomePage.aspx.cs" Inherits="User_WelcomePage" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table style="width: 560px; position: static">
    <tr>
        <td align="center" >
            Wel come To User</td>
        <td >
        </td>
    </tr>
    <tr>
        <td colspan="2">
        </td>
    </tr>
    <tr>
        <td colspan="2">
        </td>
    </tr>
    <tr>
        <td colspan="2">
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" 
                DataSourceID="SqlDataSource2" EmptyDataText="There are no data records to display."
                Style="position: static;" AllowPaging="True" PageSize="4">
                <Columns>
                    <asp:BoundField DataField="BookName" HeaderText="BookName" SortExpression="BookName" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ appSettings:OnlineDiscussionSqlCon %>"
                DeleteCommand="DELETE FROM [TblNewbookAlert] WHERE [ID] = @ID" InsertCommand="INSERT INTO [TblNewbookAlert] ([BookName]) VALUES (@BookName)"

                SelectCommand="SELECT [ID], [BookName] FROM [TblNewbookAlert]" UpdateCommand="UPDATE [TblNewbookAlert] SET [BookName] = @BookName WHERE [ID] = @ID">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="BookName" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="BookName" Type="String" />
                    <asp:Parameter Name="ID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
</table>

我尝试了很多方法,但我没有修复,

请任何人帮助我。

感谢。

1 个答案:

答案 0 :(得分:0)

请使用&#34;数据源= YourServerName \ YourSqlServerInstanceName &#34;而不是&#34;数据源=。&#34;在web.config文件中。