求助各位高手sql连接问题
具体症状就是,虽然编译没错,也能登陆sa,但好像没法从数据库里核对用户名密码,不管我怎么输入,点了登陆以后都没反应。本来应该转到default页面,但还停留在landing页面,直接就断开连接的样子,以下是代码。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
namespace RegWeb
{
public partial class landing1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=.;database=web;uid=sa;pwd=sa");
if (Session["CheckCode"].ToString().Equals(TextLoginYzm.Text.ToString()))
{
try
{
con.Open();
string md5pass = FormsAuthentication.HashPasswordForStoringInConfigFile(TextLoginPass.Text, "MD5");
SqlCommand cmd = new SqlCommand("select count(*) from LoginInfo where Name='" + TextLoginName.Text.Trim() + "' and Pass='" + md5pass + "'", con);
int i = (int)cmd.ExecuteScalar();
if (i > 0)
{
cmd = new SqlCommand("insert EntryLog(Name,LandingDate) values('" + TextLoginName.Text.Trim() + "','" + DateTime.Now.ToString() + "')", con);
cmd.ExecuteScalar();
con.Close();
Response.Redirect("Default.aspx");
}
else
{
Response.Write("<script>alert('password or id is wrong!')</script>");
}
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
else
{
Response.Write("<script>alert('验证码错误!')</script>");
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
}
}
}