SQLServer连接密码是正确的,但仍然可以使用C Sharp中的登录失败 [英] SQLServer connection Password is correct but still compain Login failed in C sharp

查看:143
本文介绍了SQLServer连接密码是正确的,但仍然可以使用C Sharp中的登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello,

我正在开发一个小的工具来收集性能数据并将数据保存在中央数据库中,因为您可以看到终端服务器可能位于不同的域中,但是奇怪的是该工具已在两个不同域中的服务器上成功运行, 当在第三个域(我们的新环境)上运行它时,它总是抱怨登录失败错误,我发现它可能与连接字符串中的Integrated Security设置有关,如果将其更改为false,则该工具无法在所有环境,但是 无论我使用什么值(SSPI,TRUE,FALSE),它都在新环境中都失败了,我尝试在此新环境中在ODBC/SMSS中使用相同的登录名,所有工作正常,实例名称,数据库名称均为正确,程序中的所有内容都是正确的 在这台新机器上无法使用.

I am developing a small tool to collect the performance data and save the data in a central database, as you can see the end servers could be in different domains, the weird thing is the tool is running successfully on our servers in two different domains, when run it on the third domain(our new environment), it always complains the login failed error, I found it might be related to the Integrated Security setting in the connection string, if I change it to false, the tool cannot work on all environments, but no matter what value I use(SSPI,TRUE,FALSE), it just failed in the new environment, I have tried to use the same login in ODBC/SMSS on this new environment, all working fine, the instance name, database name are correct, everything is correct in program, it doesn't work on this new machine.

我的环境是Windows 2012 R2 .Net 4.5

My environment is windows 2012 R2 .Net 4.5

有什么想法吗?谢谢一百万!

请查看以下详细信息:

Please see below details:

使用(SqlConnection con = new SqlConnection(@;数据源=服务器名;初始目录= dbname;集成安全性= false; UID = ReportUser; Password = 12345678"))

using (SqlConnection con = new SqlConnection(@"Data Source=servername;Initial Catalog=dbname;Integrated Security=false;UID=ReportUser;Password=12345678"))

{

...

}

日志文件查看器:

用户"ReportUser"的登录失败.原因:密码与提供的登录名不匹配. [客户:10.61.132.101]
错误:18456,严重性:14,状态:8.

Login failed for user 'ReportUser'. Reason: Password did not match that for the login provided. [CLIENT: 10.61.132.101]
Error: 18456, Severity: 14, State: 8.

C特例:

[2014年12月12日15:16:23]错误消息:System.Data.SqlClient.SqlException(0x80131904):用户'ReportUser'登录失败.     at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔型breakConnection,Action`1 wrapCloseInAction)    在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用者HasConnectionLock,布尔asyncClose)中在System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler, SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,布尔值和dataReady)    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)   位于System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔enlistOK)中  at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword, SecureString newSecurePassword,布尔值ignoreSniOpenTimeout,TimeoutTimer超时,布尔值withFailover)    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,SecureString newSecurePassword, 布尔型redirectedUserInstance,SqlConnectionString connectionOptions,SqlCredential凭据,TimeoutTimer超时)在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer超时,SqlConnectionString connectionOptions, SqlCredential凭据,String newPassword,SecureString newSecurePassword,布尔型redirectedUserInstance) 在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,SqlCredential 凭证,对象providerInfo,字符串newPassword,SecureString newSecurePassword,布尔值redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData))在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection,DbConnectionOptions userOptions))在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool 池,DbConnection owningObject,DbConnectionOptions选项,DbConnectionPoolKey poolKey,DbConnectionOptions userOptions))   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)   在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owneringObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)中在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,布尔值allowCreate,仅布尔值OneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource`1重试,DbConnectionOptions userOptions,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource`1重试,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection externalConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1 重试,DbConnectionOptions userOptions)  位于System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection externalConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1重试,DbConnectionOptions userOptions))  在System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1重试)下 在System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1重试)下 位于System.Data.SqlClient.SqlConnection.Open() 在System.Data.SqlClient.SqlBulkCopy.CreateOrValidateConnection(String 方法)  在System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount,CancellationToken ctoken)中 在System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable表,DataRowState rowState)中在ClusterServerMonitor1._0.Program.Main(String [] args)ClientConnectionId:5a9db108-fdb4-4164-b539-ae87fd9786c1

[12-Dec-2014 15:16:23] Error Message:System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'ReportUser'.    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)    at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)    at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)    at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)    at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)    at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)    at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)    at System.Data.SqlClient.SqlConnection.Open()    at System.Data.SqlClient.SqlBulkCopy.CreateOrValidateConnection(String method)    at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken)    at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)    at ClusterServerMonitor1._0.Program.Main(String[] args) ClientConnectionId:5a9db108-fdb4-4164-b539-ae87fd9786c1

使用(SqlConnection con = new SqlConnection(@数据源=服务器名;初始目录= dbname;集成安全性= SSPI; UID = ReportUser;密码= 12345678"))

using (SqlConnection con = new SqlConnection(@"Data Source=servername;Initial Catalog=dbname;Integrated Security=SSPI;UID=ReportUser;Password=12345678"))

{

...

}



推荐答案

配置错误吗?最有可能的?   UID与用户ID?

Would it be a wrong configuration? most likely?  UID vs User Id ?

;User ID=sa;Password=12345678


这篇关于SQLServer连接密码是正确的,但仍然可以使用C Sharp中的登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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