无法打开数据库 - 用户登录失败 - VB.NET 2012 MVC 4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13488974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:14:44  来源:igfitidea点击:

Cannot Open Database - The User Login Failed - VB.NET 2012 MVC 4

.netvb.netasp.net-mvc-4

提问by user1799026

Edit:The SQL connection has gotten updated.

编辑:SQL 连接已更新。

The Controller:

控制器:

Imports System.Data.SqlClient   

Function SQLSelect() As ActionResult

    Dim theconnection As New SqlConnection("Data Source=MSSQLSERVER;server=(localdb)\Projects;Database=test_drive_database;User Id=xxxx_user-PC\xxxx_user;password=;Trusted_Connection=True;Integrated Security=True;")
    theconnection.Open()

    Dim queryString As String = "SELECT * FROM ColorTable"
    Dim command As New SqlCommand(queryString)
    command.BeginExecuteNonQuery()

    command.CommandTimeout = 15
    command.CommandType = CommandType.Text

    'Printing Out the SQL Result

    Return ViewData("command")

End Function

The Error Messages:

错误信息:

Cannot open database "test_drive_database" requested by the login. The login failed.

Login failed for user 'xxxx_user-PC\xxxx_user'.

How to find out why exactly the login failed?

如何找出登录失败的确切原因?

Notice:No password is used.

注意:不使用密码。

Addendum:

附录:

        Dim theconnection As New SqlConnection("Data Source=MSSQLSERVER;server=(localdb)\Projects;Database=ColorTable_database.sdf;Integrated Security=sspi;")
    theconnection.Open()

This is also a variation I have tried, though I am getting the same error message.

这也是我尝试过的一种变体,尽管我收到了相同的错误消息。

回答by Niranjan Singh

Reference Connection strings for SQL ServerChange your connection string in the following way:

参考SQL Server的连接字符串 按以下方式更改连接字符串:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

If you want to login with default login(Window Login) then use the following one for the Trusted Connection:

如果您想使用默认登录名(窗口登录)登录,请使用以下登录名进行可信连接:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

So your connection object should be as:

所以你的连接对象应该是:

Dim theconnection As New SqlConnection("server=(localdb)\Projects; _
                          Database=test_drive_database;Trusted_Connection=True;")

If this does not solve the problem then it may be permission problem of the user. Check the reference links:

如果这不能解决问题,则可能是用户的权限问题。检查参考链接:

SQL Server Asp.Net - "Login failed"
Login failed for SQL Server user through asp.net page
SQL Server: Login failed for user
Login failed for user

SQL Server Asp.Net - “登录失败”
SQL Server 用户通过 asp.net 页面
登录失败 SQL Server:用户登录失败用户
登录失败

回答by GiantHornet

try to add "Trusted_Connection = true;" on the connection string.

尝试添加“Trusted_Connection = true;” 在连接字符串上。