我已经能够使用此连接字符串创建一个新数据库:
SqlConnection myConn = new SqlConnection("Server=.\\SQLEXPRESS;Integrated security=True;User Instance=True");
但是,当我使用此连接字符串创建表时:
SqlConnection connection = new SqlConnection("Server=.\\SQLEXPRESS;Database='FormsDB';Integrated security=True;User Instance=True");
它为用户提供了登录失败
我到目前为止尝试过:
SqlConnection connection = new SqlConnection(@"Server=.\SQLEXPRESS;Initial Catalog='FormsDB';Integrated security=True;User Instance=True;Trusted_Connection=True;");
我收到同样的错误消息:
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "FormsDB" requested by the login. The login failed. Login failed for user 'LC-SURF\Tums'. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at .....
任何建议都将不胜感激。
谢谢。
答案 0 :(得分:-2)
此格式的连接字符串,您必须使用sa帐户登录SQL Server。
string ConnectionString = @"Data Source = .\SQLEXPRESS;Initial Catalog = FormsDB;Integrated Security = True; User Id = sa; Password = sql";