“错误”;用户“登录失败”;带SQLConnection的C#
我创建了一个数据库(没有用户或密码)作为基于服务的数据库 现在我正在尝试插入数据库,但出现错误“用户登录失败” 我有以下代码:“错误”;用户“登录失败”;带SQLConnection的C#,c#,C#,我创建了一个数据库(没有用户或密码)作为基于服务的数据库 现在我正在尝试插入数据库,但出现错误“用户登录失败” 我有以下代码: string J_connetionString1 = null; SqlConnection J_connection1; SqlDataAdapter J_adapter1 = new SqlDataAdapter(); string J_sql1 = null; J_connetionString1 = @"Data Source=.\SQLEXPRESS;Ini
string J_connetionString1 = null;
SqlConnection J_connection1;
SqlDataAdapter J_adapter1 = new SqlDataAdapter();
string J_sql1 = null;
J_connetionString1 = @"Data Source=.\SQLEXPRESS;Initial Catalog=J_InsData";
J_connection1 = new SqlConnection(J_connetionString1);
J_sql1 = "update instinfo set instinfoNAME = textBox2.text where instinfoID ='1'";
try
{
J_connection1.Open();
J_adapter1.UpdateCommand = J_connection1.CreateCommand();
J_adapter1.UpdateCommand.CommandText = J_sql1;
J_adapter1.UpdateCommand.ExecuteNonQuery();
MessageBox.Show("Row updated !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
我不能评论,所以我编辑了Q
使用此代码时出现此错误
错误:
system.Data.sqlclint.sqlexpection(0x80131904)
无法通过登录打开数据库“J_InsData”请求。登录失败
用户J-PC登录失败\J
代码:
J_connetionString1=@“数据源=。\SQLEXPRESS;初始目录=J_InsData;可信连接=True;集成安全=SSPI” 您是否尝试将以下内容添加到连接字符串中
Integrated Security=True
或
这跟真的差不多
这可能对您也有用 您需要告诉SQL Server用于连接的用户凭据 因此,您应该在连接字符串中提供SQL Server用户的用户id和密码
Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;
另一方面,如果SQL Server配置为接受windows域用户,则可以在连接字符串中使用Integrated Security=SSPI或Trusted_Connection=True
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Server=myServerAddress;Database=myDataBase;Integrated Security=SSPI;
使用以下连接字符串
@“数据源=。\SQLEXPRESS;初始目录=J_InsData;集成安全性=SSPI”代码>
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Server=myServerAddress;Database=myDataBase;Integrated Security=SSPI;