C# 数据库连接问题
我是新手,请教下:以下是C#源代码,不知道什么问题,怎么都连接不上数据库..问是在执行了catch里(已标色)了:text = login_username.Text;
key = login_password.Text;
string str = "user id=sa;password=xjjy287094;";
//string str="Trusted_Connection=SSPI;";//自动登陆时使用的
str += @"initial catalog=St_china_elc;Server=(local)\SQL2005;integrated security=True;";
//str+=@"Server=WWW-9EB2192731B\SQL2005;initial catalog=St_china_elc;Integrated Security=True;";
str+="Connect Timeout=30";
// string str=@"Data Source=WWW-9EB2192731B\SQL2005;Initial Catalog=St_china_elc;Integrated Security=True using System;";
SqlConnection con = new SqlConnection(str);
try
{
con.Open();
if (con == null)
{
Response.Redirect("PasswordChange.aspx");
}
login_username.Text = "hdu";
login_password.Text = "dj";
string strsql = "select Users_UserName from Users where Users_UserName=" + login_username.Text + "and Users_Password=" + login_password.Text;
SqlDataAdapter da = new SqlDataAdapter(strsql, con);
DataSet ds = new DataSet();
int count = da.Fill(ds, "table");
if (count > 0)
{
lab_test1.Visible = true;
Response.Redirect("PasswordChange.aspx");
}
else
{
Response.Write("<script>alert('<font color=red>不存在的用户名</font>')");
lab_test1.Text = "登陆失败";
lab_test1.Visible = true;
}
}
catch (Exception ex)
{
lab_test1.Text = "连接\\登陆失败";
lab_test1.Visible = true;
}
finally
{
login_username.Text = "hdu";
login_password.Text = "dj";
con.Close();
}
}