[英]Connected to Unknown Database in Entity Framework
Here is my connection string in web.config: 这是我在web.config中的连接字符串:
Note database name isn't there in connection string, but I can perform all CRUD operations using EF in MVC 5. 注意,连接字符串中没有数据库名称,但是我可以在MVC 5中使用EF执行所有CRUD操作。
Can someone tell how I can get to which database I am connected in MSSQL Server. 有人可以告诉我如何在MSSQL Server中连接到哪个数据库。
As per @lad2025's comment, because the connection string has omitted the Database (or Initial Catalog
) definition, so the connection will default to the default database assigned to the login used to connect to the server ( sa
in your case). 根据@ lad2025的注释,由于连接字符串省略了Database(或Initial Catalog
)定义,因此该连接将默认为分配给用于连接服务器的登录名的默认数据库(在您的情况下为sa
)。
There are a number of ways to find the database 有多种找到数据库的方法
sp_who
(as you already have sa
access) and look up the dbname
column for the connection. 或者,一旦您的应用程序具有活动的连接,请运行sp_who
(因为您已经具有sa
访问权限)并在dbname
列中查找该连接。 You should however address this behaviour: 但是,您应该解决此问题:
sa
as a login. 切勿让应用使用sa
作为登录名。 The login should be restricted to the minimum set of accesses required 应将登录名限制为所需的最小访问权限集 You can check default database using SQL Server Management Studio
: 您可以使用SQL Server Management Studio
检查默认数据库:
Object Explorer -> Server -> Security -> Logins -> sa -> right click -> check default database
Something like: 就像是:
Image source: http://www.mytechmantra.com/LearnSQLServer/Fix-cannot-open-user-default-database-Login-failed-Login-failed-for-user-SQL-Server-Error/ 图片来源: http : //www.mytechmantra.com/LearnSQLServer/Fix-cannot-open-user-default-database-Login-failed-Login-failed-for-user-SQL-Server-Error/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.