none
Need to connect to SQL Server 2017 RRS feed

  • Question

  • I have installed SQL Server 2017 on Windows 10 and using Excel VBA 2016.  I am trying to connect to the database. My login to SQL Server looks like this:

    Server Type = Database Engine

    Server Name = ALIEN

    Authentication = Windows Authentication

    Username = ALIEN/rhcas

    Password is blank

    And my code looks like this:

        Dim Cn As ADODB.Connection
        Dim Server_Name As String, Database_Name As String, User_ID As String, Password As String, SQLStr As String
        Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
        Set Cn = New ADODB.Connection
        Cn.Open "Driver={SQL Server};Server=" & "ALIEN" & ";Database=" & "NetApp" & _
        ";Uid=" & "ALIEN\rhcas" & ";"

        Cn.Open "Driver={SQL Server};Server=" & "ALIEN" & ";Database=" & "NetApp" & _
        ";Uid=" & "ALIEN\rhcas" & ";Pwd=" & Null & ";"

        Cn.Open "PROVIDER=SQLOLEDB;Server=" & "ALIEN" & ";Database=" & "NetApp" & _
        ";Uid=" & "rhcas" & ";Pwd=" & Null & ";"

    For all three Open statements the error message is:

    Run-time error '-2147217841 (80040e4d)':

    [Microsoft][ODBC SQL Server Driver]{SQL Server]Login failed for User 'ALIEN\rhcas'.   or 'rhcas'

    What is wrong?

    Sunday, October 15, 2017 6:39 PM

All replies

  • Hi RHCase,

    Since you are using Window Authentication for logging, I think there is no need for setting Uid/PWD. Please try below connect string.

    Cn.Open "Provider=SQLOLEDB;Data Source=TestServer;Trusted_connection=yes;"

    Best Regards,

    Terry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, October 16, 2017 2:16 AM
  • Thanks Terry, that seems to have worked.
    Monday, October 16, 2017 4:57 PM
  • Hi RHCase,

    I'm glad to hear that your original issue has been resolved. I would suggest you mark useful reply to close this thread. If you have any other issue, please feel free to post thread to let us know.

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 17, 2017 5:31 AM