none
Password is correct but still compain Login failed in C sharp RRS feed

  • 问题

  •  Hello,

    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... Any ideas?

    Please see below details:

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

    {

    ...

    }

    Log File Viewer:

    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 Sharp exception:

    [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


    • 已编辑 AlbertZOZ 2014年12月16日 5:51 remove confidential info
    2014年12月12日 4:46

答案

  • hi, AlbertZOZ

    as per the errorlog 

    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.

    the error number 18456 has a few status to show the meaning of the error

    one of the status is 8

    the status description bellow shows that your pwd is incorrect

    Error: 18456, Severity: 14, State: 8
    
    --每个18456错误会返回一个状态编号,每个编号都有它自己的意思
    --根据编号的含义确定错误的原因
    --状态   说明
    --8       密码不正确
    

    If you did not find any other error,double  check your  password pls

    thanks


    2014年12月13日 3:14
  • can u drag and drop a sql connection object in design panel and try to follow the wizard and test it?

    You may also try to follow this article to fix it.

    http://blogs.msdn.com/b/sqlsakthi/archive/2011/02/06/how-to-troubleshoot-connectivity-failure-error-with-sql-server.aspx


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.


    2014年12月22日 4:12

全部回复

  • You have uid WiseGridReportUser in connection string but server says login failed for user ReportUser, you sure connection string is correct?
    2014年12月13日 2:15
  • hi, AlbertZOZ

    as per the errorlog 

    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.

    the error number 18456 has a few status to show the meaning of the error

    one of the status is 8

    the status description bellow shows that your pwd is incorrect

    Error: 18456, Severity: 14, State: 8
    
    --每个18456错误会返回一个状态编号,每个编号都有它自己的意思
    --根据编号的含义确定错误的原因
    --状态   说明
    --8       密码不正确
    

    If you did not find any other error,double  check your  password pls

    thanks


    2014年12月13日 3:14
  • same program is used in other computers...
    2014年12月14日 22:05
  • 1) Could you check if "WiseGridReportUser" is a SQL user?

    2) If you look into MSDN, you will find these message,

    Value in Integrated Security:

    "When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication.

    Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true."

    So if you specified SSPI or true, it will pass the current windows credentail when accessing DB. It will ignore the UID and password that you have given in connection string. If you really want to pass with UID and password value, you should choose "Integrated Security=FALSE"

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(VS.71).aspx


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.

    2014年12月15日 1:48
  •  password is hardcoded in program, so if it works on other machines, it should work on this one, I also tried to use the password by SMSS, ODBC all worked...
    2014年12月15日 6:30
  • Thanks KenLin,

    I tried all those three values, all failed. If use true/SSPI, the error is different:

    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    I am wondering why I can use this sql user to connect to the database by SSMS and ODBC, just my program not...

    2014年12月15日 6:34
  • hi ,albertZOZ

    there is another tool could help you to catch the network packet

    such as Wireshark , netmon to look at the packets and checking what's going go between your program and sql

    2014年12月15日 6:54
  • Thanks KenLin,

    I tried all those three values, all failed. If use true/SSPI, the error is different:

    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    I am wondering why I can use this sql user to connect to the database by SSMS and ODBC, just my program not...

    Did you set "Integrated Security=False"? What is the result?

    The reason why it returns such error when you set to true/SSPI, because the new 3rd domain is not being in trust-relationship with the first domain. You have to configure it in domain controller.


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.

    2014年12月15日 8:08
  •  password is hardcoded in program, so if it works on other machines, it should work on this one, I also tried to use the password by SMSS, ODBC all worked...

    Try to look at the log in the target SQL server, to see what username and password was sent from the new PC/server to the SQL Server.

    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.

    2014年12月15日 8:09
  • Thanks KenLin,

    I tried all those three values, all failed. If use true/SSPI, the error is different:

    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    I am wondering why I can use this sql user to connect to the database by SSMS and ODBC, just my program not...

    Does your app  connect to correct sql instance?
    2014年12月15日 14:51
  • False:

    Login failed for user 'ReportUser'.  

    SSPI/True:

    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    I was thinking the same thing, which the domain is the cause, I will double check this with other engineer.

    2014年12月16日 5:30
  • Can see log which saying the login failed, but no password information.
    2014年12月16日 5:30
  • yes, tried ODBC/SMSS/Ping all working fine.
    2014年12月16日 5:31
  • but even they are not being in trust-relationship, the false mode should work, isn't it?
    2014年12月16日 5:46
  • Is the domain of the SQL server different from the domain of the new app server?

    What is the "ReportUser" belongs to? A domain user account or a SQL user account?

    If it is a domain user account, could you try to change the UID into "{SQLServer_Domain_Name}\ReportUser"?


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.


    2014年12月16日 5:58
  • sql user account
    2014年12月22日 4:00
  • can u drag and drop a sql connection object in design panel and try to follow the wizard and test it?

    You may also try to follow this article to fix it.

    http://blogs.msdn.com/b/sqlsakthi/archive/2011/02/06/how-to-troubleshoot-connectivity-failure-error-with-sql-server.aspx


    大家一齊探討、學習和研究,謝謝!
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD,
    MCT, Microsoft Community Star(TW & HK),
    Microsoft MVP for VB.NET since 2003
    My MSMVP Blog

    請記得將對您有幫助的回覆標示為解答以幫助其他尋找解答及參與社群討論的朋友們。
    Please remember to clickMark as Answer on the post that helps you. This can be beneficial to other community members reading the thread.


    2014年12月22日 4:12