用户的数据库登录失败 [英] Database login failed for user

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

问题描述

我知道这个问题会不时地重复,但是我在这里尝试了几乎所有答复,但是仍然遇到下面的代码尝试连接到我的MS SQL Server 2014的问题:

I am aware that this question repeats from time to time but I tried almost every response here and I still encounter a problem with code below that tries to connect to my MS SQL Server 2014:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "(LocalDB)\\v11.0";
builder.UserID = "LOGIN";
builder.Password = "PASSWORD";
builder.InitialCatalog = "DATABASE";
builder.IntegratedSecurity = false;
SqlConnection connection = new SqlConnection(builder.ConnectionString);
connection.Open();

我用密码PASSWORD创建了一个用户登录:

I created an user LOGIN with password PASSWORD:

CREATE LOGIN [LOGIN] WITH
PASSWORD=N'PASSWORD',
DEFAULT_DATABASE=[DATABASE],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=ON

并启用帐户。

alter login LOGIN enable

我检查了我的Microsoft SQL Server 2014 Management Studio用户LOGIN是否在Security文件夹中,并且在Database Secuirty Users文件夹中是否还包含用户LOGIN。

I checked if in my Microsoft SQL Server 2014 Management Studio user LOGIN is in Security folder and in Database Secuirty Users folder also contains User LOGIN.

我也尝试了在我的Visual Studio中使用Windows身份验证连接到数据库,我成功了。但是,即使尝试执行以下代码,我也无法使用上面的代码重复此连接过程:

I tried also using Windows Authentication in my Visual Studio to connect to database and I succeeded. However I cannot repeat this connection process with my code above even when I try to execute the code below:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "(LocalDB)\\v11.0";
builder.InitialCatalog = "DATABASE";
builder.IntegratedSecurity = true;
SqlConnection connection = new SqlConnection(builder.ConnectionString);
connection.Open();

我收到以下错误:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'LOGIN'.
    in System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
    in System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
    in System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
    in System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
    in System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
    in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
    in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
    in System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
    in System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
    in System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
    in System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
    in System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
    in System.Data.SqlClient.SqlConnection.Open()

此数据库是我的服务器上的新数据库;昨天我进行了一次新安装,据我所知,我使用的是默认安装设置。

This database is new on my server; I made a new installation yesterday and I used default installation settings as far as I remember.

推荐答案

我要感谢您您的答案。解决方案在下面的代码中:

I would like to thank you for your answers. Solution is in code below:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = ".";            // DataSource changed             
builder.InitialCatalog = "DATABASE";
builder.IntegratedSecurity = true;
SqlConnection connection = new SqlConnection(builder.ConnectionString);
connection.Open();

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

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