首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

.net 配置文件连接数据库疏失

2013-06-25 
.net 配置文件连接数据库出错http://msdn.microsoft.com/zh-cn/library/taab950e(vvs.100).aspx我按照这

.net 配置文件连接数据库出错
http://msdn.microsoft.com/zh-cn/library/taab950e(v=vs.100).aspx
我按照这个网站写了个简单例程,在连接数据库的配置上出错了
不懂是哪里出错,请熟悉的人指导,谢谢。

报错如下:
.net 配置文件连接数据库疏失

aspx的代码如下:


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test_profile.aspx.vb" Inherits="test_profile.test_profile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat ="server" >
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        labelPostalCode.Text = Profile.PostalCode
    End Sub
    
    Sub SetPostalCode_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs)
        Profile.PostalCode = Server.HtmlEncode(textPostalCode.Text)
        labelPostalCode.Text = Profile.PostalCode
    End Sub
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="textPostalCode" runat="server"></asp:TextBox>
        <asp:Button ID="SetPostalCode" runat="server" Text="Button" OnClick="SetPostalCode_Click"
/>
        <asp:Label ID="labelPostalCode" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

web.congfig文件如下:

<?xml version="1.0" encoding="utf-8"?>

<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="LocalSqlServer"
       connectionString="server=PC-20121108IOLX;database=test_profile;Integrated Security=SSPI;"
       providerName="System.Data.SqlClient"
   />
  </connectionStrings>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    <anonymousIdentification enabled="true" />
    <profile>
      <properties>
        <add name="PostalCode"         type="System.String"         allowAnonymous="true" />
      </properties>
    </profile>

    <!-- other Web.config settings here -->
  </system.web>

</configuration>



配置文件 数据库
[解决办法]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<script language="c#" runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox tbox = (TextBox)Page.FindControl("TextBox1");
        string a = System.Web.HttpUtility.HtmlEncode(tbox.Text);
        Response.Write(a);
    }
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

热点排行