我是asp.net和sql server的初学者。我使用sql认证在sql server 2014中创建了一个数据库。如何在ASP.NET中解决这个错误
这里是我的代码:
Registration.aspx.cs
public partial class Registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-U9DUN78\SQLEXPRESS;Initial Catalog=LoginRegisterData;Persist Security Info=True;User ID=sa;Password=***********;Pooling=False");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into UserDetails values('" + TextBoxUsername.Text + "','" + TextBoxEmailid.Text+ "','" + TextBoxPassword.Text + "','" + TextBoxDate.Text + "','" + DropDownListCountry.SelectedItem + "')";
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ee)
{
Response.Write(ee);
}
}
我想将数据存储到SQL Server数据库。下面的卡扣是我得到的错误:
在连接字符串中检查您的密码传递给SqlConnection的字符串完全匹配您在SSMS中使用的密码; – techspider
根据您的错误,听起来您的凭据不正确。尝试使用相同的登录到SQL Server Management Studio来查看是否有帮助。另外,请考虑使用参数来构建查询,而不是串联字符串。 –
正如前面的用户指出的那样(确认证书)您可以在您想要打开连接的代码中指向断点。 其他建议: 1.不要使用“sa”作为你的网络应用sql连接 - 非常危险的做法 2.使用@ – DaniDev