代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            Response.Write("success");
            Response.Redirect("Home.aspx");
        }    }
    private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
    {        bool boolReturnValue = false;        // Insert code that implements a site-specific custom         // authentication method here.        // This example implementation always returns false.        string strConnection = "server=(local);database=huatian-info;uid=sa;pwd=;";        SqlConnection Connection = new SqlConnection(strConnection);        String strSQL = "Select * From User";        SqlCommand command = new SqlCommand(strSQL, Connection);        SqlDataReader Dr;        Connection.Open();        Dr = command.ExecuteReader();        while (Dr.Read())
        {            if ((UserName == Dr["User_Code"].ToString()) & (Password == Dr["Password"].ToString()))
            {                boolReturnValue = true;                break;            }        }        Dr.Close();        return boolReturnValue;    }}错误提示:
源错误: 
行 52:         SqlDataReader Dr;
行 53: 
行 54:         Connection.Open();
行 55: 
行 56:         Dr = command.ExecuteReader();
 源文件: e:\web\huatian-info\login.aspx.cs    行: 54 请帮忙告诉原因 谢谢 解决后马上散分!

解决方案 »

  1.   

    连接字符串改成这个试试:
    String strConnection="Data Source=(local);Initial Catalog=huatian-info;uid=sa;pwd=;"
      

  2.   

    还是不行 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'User' 附近有语法错误。源错误: 
    行 55:         Connection.Open();
    行 56: 
    行 57:         Dr = command.ExecuteReader();
    行 58:          
      

  3.   

    User是Sqlserver的保留关键字,你查询的时候改成[User]试下,就是在User外面加上[].
      

  4.   

    "server=(local);database=huatian-info;uid=sa;pwd=;"
    ---------------------------------------------------------------------------
    最后引号里的那个分号去掉!
      

  5.   

    pcb_ghl  是对的 我忘记了 ...sorry !
    散分