Microsoft Knowledge Base Email Alertz

(304310) - If a Microsoft SQL Server password includes trailing spaces, the OLE DB Provider for SQL Server (SQLOLEDB) ignores or removes those spaces before it passes the credentials to the backend server. In addition, you receive the following error message:...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 304310 - Last Review: November 5, 2003 - Revision: 3.0

BUG: SQLOLEDB Provider Ignores or Removes Trailing Spaces from Password on the Connection Open Method

This article was previously published under Q304310

On This Page

SYMPTOMS

If a Microsoft SQL Server password includes trailing spaces, the OLE DB Provider for SQL Server (SQLOLEDB) ignores or removes those spaces before it passes the credentials to the backend server. In addition, you receive the following error message:
Run-time error '-2147217843(80040e4d)':
Login failed for user 'UserName'.
This problem does not occur with OLE DB Provider for ODBC Drivers.

RESOLUTION

To work around this problem, use the OLE DB Provider for ODBC Driver instead of the OLE DB Provider for SQL Server, or do not create passwords with trailing spaces.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a new Standard EXE project in Microsoft Visual Basic 6.0. Form1 is created by default.
  2. Set a reference to Microsoft ActiveX Data Objects 2.X.
  3. Copy and paste the following code into the code window of Form1:

    Note You must change User ID=<UID> and password=<strong password> to the correct values before you run this code. Make sure that <UID> has the appropriate permissions to perform this operation on the database.
    Private Sub Form_Load()
    
    Dim cn As New Connection
    Dim cn2 As New Connection
    Dim cn3 As New Connection
    
        cn.Open "Provider=sqloledb;Data source=scout333;" & _
         "User ID=<UID>;Password=<strong password>;initial catalog=northwind"
    On Error Resume Next
        cn.Execute "sp_revokedbaccess 'User1'"
        cn.Execute "sp_droplogin 'User1'"
        
    On Error GoTo 0
        cn.Execute "sp_addlogin 'User1', 'Test   ', 'Northwind'"
        cn.Execute "sp_adduser 'User1', 'User1'"
    
        cn2.Open "Provider=MSDASQL;Driver=sql server;" & _
         "server=scout333;UID=User1;PWD=Test   ;"
        MsgBox "Connection State: " & cn2.State
        cn3.Open "Provider=sqloledb;Data source=scout333;" & _
         "User ID=User1;Password=Test   ;"
    
    End Sub
    					
  4. Be sure to change the connection string for the cn object so it correctly uses an existing SQL Server log on. Also, change the connection strings for the cn2 and cn3 objects so they correctly point to your SQL Server.
  5. Run the code. When the connection that uses the OLE DB Provider for ODBC Drivers connects, you receive confirmation of this connection in a message box. This message box contains a connection state of 1 (adStateOpen) if the connection is made properly.
  6. Click OK in the message box. The code attempts to make the connection by using the OLE DB Provider for SQL Server. This fails with the above-mentioned error message.

REFERENCES

For additional information about opening ADO connections, click the following article number to view the article in the Microsoft Knowledge Base:
168336  (http://kbalertz.com/Feedback.aspx?kbNumber=168336/ ) HOWTO: Open ADO Connection and Recordset Objects

APPLIES TO
  • Microsoft OLE DB Provider for SQL Server 7.0
  • Microsoft OLE DB Provider for SQL Server 7.01
Keywords: 
kbbug kbnofix kbprovider KB304310
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate