无法打开登录请求的数据库“...”。登录失败。用户'...'登录失败 [英] Cannot open database “…” requested by the login. The login failed. Login failed for user '…'

查看:115
本文介绍了无法打开登录请求的数据库“...”。登录失败。用户'...'登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为项目创建了安装文件(已经包含了所有.mdf和.ldf文件)。当我在我的电脑上安装时,没关系。但是,如果我带到另一台PC,安装 - >好的,但是运行 - >得到错误



无法打开数据库 站立。登录失败。登录失败 用户 (PC名称) 







在源代码中,我使用3个带有3个connectionString的数据库,如下所示: />


  public   void  LoadDB()
{
conDB = new SqlConnection();
conDB.ConnectionString = @ 数据源= .\SQLEXPRESS;
AttachDbFilename = C: \EPL.mdf;
Integrated Security = True;
Connect Timeout = 30;
User Instance = True
;
conDB.Open();

conFix = new SqlConnection();
conFix.ConnectionString = @ 数据源= .\SQLEXPRESS;
AttachDbFilename = C: \ Fixtures.mdf;
Integrated Security = True;
Connect Timeout = 30;
User Instance = True
;
conFix.Open();

conStan = new SqlConnection();
conStan.ConnectionString = @ 数据源= .\SQLEXPRESS;
AttachDbFilename = C: \ Standing.mdf;
Integrated Security = True;
Connect Timeout = 30;
User Instance = True
;
conStan.Open();
}





我该怎么办?

解决方案

1。如果是Microsoft SQL Server Express,您应该尝试以下操作:



 Server =(localdb)\ v11.0; Integrated Security = true; 
AttachDbFileName = C:\ MyFolder \ MyData.mdf;





  public   void  LoadDB()
{
conDB = new SqlConnection();
conDB.ConnectionString = @ Server =(localdb)\ v11.0;
Integrated安全性=真;
AttachDbFilename = C:\EPL.mdf
;
conDB.Open();
}





这应该适合你。



2.您使用SQL服务器还是Windows身份验证?如果您在连接字符串中使用SQL Server身份验证

我相信您还应该提供:User ID = myUsername;密码= MYPASSWORD; :



  public   void  LoadDB()
{
conDB = new SqlConnection();
conDB.ConnectionString = @ Server =(localdb)\ v11.0;
Integrated Security = True;
AttachDbFilename = C:\ EPL.mdf;
User ID = myUsername;
Password = myPassword
;
conDB.Open();
}


I have created the setup file for a project (already have all of .mdf and .ldf files). When I install on my PC, it's OK. But If I bring to another PC, Install --> OK, but Run --> get the error

Cannot open database "Standing" requested by the login. The login failed. Login failed for user "(name of PC)"




In source code, I use 3 databases with 3 connectionString like this:

public void LoadDB()
{
    conDB = new SqlConnection();
    conDB.ConnectionString = @"Data Source=.\SQLEXPRESS;
                  AttachDbFilename=C:\EPL.mdf;
                  Integrated Security=True;
                  Connect Timeout=30;
                  User Instance=True";
    conDB.Open();

    conFix = new SqlConnection();
    conFix.ConnectionString = @"Data Source=.\SQLEXPRESS;
                  AttachDbFilename=C:\Fixtures.mdf;
                  Integrated Security=True;
                  Connect Timeout=30;
                  User Instance=True";
    conFix.Open();

    conStan = new SqlConnection();
    conStan.ConnectionString = @"Data Source=.\SQLEXPRESS;
                  AttachDbFilename=C:\Standing.mdf;
                  Integrated Security=True;
                  Connect Timeout=30;
                  User Instance=True";
    conStan.Open();
}



What should I do?

解决方案

1. If it's Microsoft SQL Server Express you should try the following:

Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName=C:\MyFolder\MyData.mdf;



public void LoadDB()
{
    conDB = new SqlConnection();
    conDB.ConnectionString = @"Server=(localdb)\v11.0;
                  Integrated Security=True;
                  AttachDbFilename=C:\EPL.mdf";
    conDB.Open();
}



This should work for you.

2. Do you use SQL server or Windows authentication ? If you're using SQL server authentication
in your connection string I believe that you should also provide: User ID=myUsername; Password=myPassword; :

public void LoadDB()
{
    conDB = new SqlConnection();
    conDB.ConnectionString = @"Server=(localdb)\v11.0;
                  Integrated Security=True;
                  AttachDbFilename=C:\EPL.mdf;
                  User ID=myUsername;
                  Password=myPassword";
    conDB.Open();
}


这篇关于无法打开登录请求的数据库“...”。登录失败。用户'...'登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆