无法打开登录请求的数据库

时间:2019-06-07 11:59:09

标签: c# sql-server-2014

我已在Visual Studio 2017中创建了WCF服务。我正在尝试与SQL Server Management Studio 2014建立服务连接。

  

无法打开登录请求的数据库“ DatabaseName”。登录失败。用户“ admin”的登录失败。

我从Youtube和其他网站尝试了以下解决方案。但这对我不起作用。

https://blog.sqlauthority.com/2009/08/20/sql-server-fix-error-cannot-open-database-requested-by-the-login-the-login-failed-login-failed-for-user-nt-authoritynetwork-service/

我的代码如下:

 string sdwConnectionString = @"Data Source = DESKTOP-JSKR320; user id= admin; password= Password; Initial Catalog = DatabaseName;";

 try 
 {
     SqlConnection connection = new SqlConnection(sdwConnectionString);
     using (connection)
     {
         connection.Open();    
         using (var command = connection.CreateCommand())
         {
             command.CommandType = CommandType.StoredProcedure;
             for (int i=0; i<walls.Count; i++)
             {
                 command.CommandText = "addWall ";    
                 command.Parameters.AddWithValue("floorid", walls[i].floorid);
                 command.Parameters.AddWithValue("x1",walls[i].x1);
                 command.Parameters.AddWithValue("y1",walls[i].y1);
                 command.Parameters.AddWithValue("x2",walls[i].x2);
                 command.Parameters.AddWithValue("y2",walls[i].y2);
             }
             command.ExecuteNonQuery();
         }
         added = true;
     }
 }
 catch (Exception ex)
 {
     Console.WriteLine(ex.Message);
 }

0 个答案:

没有答案