web.confing代码:
Default.aspx代码:

    <title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
    
</div>
    
<asp:TextBox ID="login_username" runat="server"></asp:TextBox>
    
<p>
        
<asp:TextBox ID="login_userpwd" runat="server"></asp:TextBox>
    
</p>
    
<p>
        
&nbsp;</p>
    
<asp:Button ID="login_button" runat="server" onclick="login_button_Click" 
        Text
="Button" />
    
<br />
    
<asp:TextBox ID="view" runat="server"></asp:TextBox>
    
</form>
</body>
</html>

Default.aspx.cs代码:
 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    
protected void login_button_Click(object sender, EventArgs e)
    {
        
string u_name, u_pwd;
        u_name 
= login_username.Text.Trim();
        u_pwd 
= login_userpwd.Text.Trim();
        
string connectionString = ConfigurationSettings.AppSettings["connstring"];
        SqlConnection conn 
= new SqlConnection(connectionString);
        
string sqlStr = "select * from user_info where user_name = '"+u_name.ToString()+"' and user_pwd = '"+u_pwd.ToString()+"'";
        conn.Open();
        SqlCommand cmd 
= new SqlCommand(sqlStr, conn);
        SqlDataReader dr 
= cmd.ExecuteReader();
        
if (dr.Read())
        {
            view.Text 
= "对了!";
        }
        
else{
            view.Text 
= "用户名或者密码错误";
        }
        conn.Close();
    }

}


sql数据库配置记录:
1、服务和连接的外围应用配置器-Database Engine-sqlexpress--远程连接-本地连接和远程连接-同时使用TCP/IP和named pipes
2、服务和连接的外围应用配置器-SQL Server Browser-服务-启动类型-自动
3、SQL Server Configuration Manager-Sql Server(SQLEXPRESS)-右键属性-登陆-登陆身份为:内置帐户-local system

(这步看来是多余的,还是使用Network Service,如果使用local system,则会导致使用ASP.NET SQL Server安装向导时连接不上sql server | 汗,后来发现是服务器名的问题,ASP.NET SQL Server安装向导中的服务器名,以后最好打开Mircosoft SQL Server Management Studio Express看下复制过来最好,我设置成MICHAEL/EXPTESS就可以了,郁闷)
4、Mircosoft SQL Server Management Studio Express-右键“服务器”-属性-安全性-服务器身份验证:SQL Server和Windows身份验证模式
5、新建“NDWORK_OA_SYSTEM”数据库,新建“user_info”表,列表为user_id;user_name;user_pwd.
6、Mircosoft SQL Server Management Studio Express-服务器-安全性-新建登录名-登录名:zx;SQL Server 身份验证-密码:123;去掉“用户在下次登陆时必须更改密码”;默认数据库:NDWORK_OA_SYSTEM.
7、NDWORK_OA_SYSTEM-安全性-用户-新建用户-用户名:zx;登录名:zx;“此用户拥有的架构”、“数据库角色成员身份”均设为db_owner(这里还有的疑问,架构和角色有什么区别,还有默认架构时怎么回事)

相关文章:

  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-06-16
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案