无法在SQL 2008中打开与数据库的SQL连接

时间:2021-07-12 13:35:12

I'm trying to connect to a database running on my local machine from my web application. I can connect to other databases that I created but not this one that I restored from another server. I can connect to the database using the MS SQL Server Management Console and see the database contents, tables etc. but when I try to open an SQL connection I get the error:

我正在尝试从我的Web应用程序连接到本地计算机上运行的数据库。我可以连接到我创建的其他数据库,但不能连接到我从其他服务器恢复的数据库。我可以使用MS SQL Server管理控制台连接到数据库并查看数据库内容,表等,但是当我尝试打开SQL连接时,我收到错误:

"Cannot open database "[Database Name]" requested by the login. The login failed. Login failed for user '[DOMAIN\USERNAME]'"

“无法打开数据库”[数据库名称]“登录请求。登录失败。用户'[DOMAIN \ USERNAME]'登录失败

I have tried setting the login properties User Mapping to dbo and set database role membership to db_owner. I also tried switching to mixed mode where I created a SQL account which also works in management studio but not in my application. My application code works with other databases so it's not the connection string, must be a permissions problem but I'm not seeing it. Any ideas?

我已尝试将登录属性User Mapping设置为dbo,并将数据库角色成员身份设置为db_owner。我也试过切换到混合模式,我创建了一个SQL帐户,该帐户也可以在管理工作室中使用,但不能在我的应用程序中工我的应用程序代码与其他数据库一起使用,因此它不是连接字符串,必须是权限问题,但我没有看到它。有任何想法吗?

1 个解决方案

#1


5  

When bringing over a backup from another server, the login names that exist under Security\Users is no longer valid because those logins (even though they are mapped to Windows accounts) are valid only for the server the database was on.

从其他服务器引入备份时,Security \ Users下存在的登录名不再有效,因为这些登录(即使它们映射到Windows帐户)仅对数据库所在的服务器有效。

In effect, you will have to remove and then re-add the logins.

实际上,您必须删除然后重新添加登录。

#1


5  

When bringing over a backup from another server, the login names that exist under Security\Users is no longer valid because those logins (even though they are mapped to Windows accounts) are valid only for the server the database was on.

从其他服务器引入备份时,Security \ Users下存在的登录名不再有效,因为这些登录(即使它们映射到Windows帐户)仅对数据库所在的服务器有效。

In effect, you will have to remove and then re-add the logins.

实际上,您必须删除然后重新添加登录。