+ Reply to Thread
Results 1 to 3 of 3

Facing 'run-time error -2147217871 (80040e31) Automation error' in excel VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-25-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Facing 'run-time error -2147217871 (80040e31) Automation error' in excel VBA

    Hi guys,

    I am working on Excel 2007 macros. My requirement is to access MS SQL server DB from excel, using VBA. I am just trying to pull some data by connecting to DB, but facing this issue: 'Facing 'run-time error -2147217871 (80040e31) Automation error' in excel VBA'

    Below is the chunk of code I am using:

    Dim objMyConn
    Set objMyConn = New ADODB.Connection
    Dim objMyRecordset As New Recordset
    Set objMyRecordset = New ADODB.Recordset
    Dim strConnectionString As String
    Dim strSQL As String
    
    strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog={abcd};Data Source={abcd};Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID={abcd};Use Encryption for Data=False;Tag with column collation when possible=False;ConnectionTimeout = 300;CommandTimeout = 0;"
    
    strConnectionString = "Driver=SQL Server;Server={abcd};UID=;PASSWORD=;Database={abcd};Trusted_Connection=Yes;"
    
    strSQL = "select top 10 * from {table name} where server = '{columnName}' order by 1 desc"
    
    objMyConn.Open strConnectionString
    
    objMyRecordset.Open strSQL, objMyConn
    
    ActiveSheet.Range("A4").CopyFromRecordset objMyRecordset
    For reference, I have pasted here both the connection strings which I tried. With both I am facing the same issue.

    Any help is appreciated. Thanks.

    Moderator Note:

    Pls use code tags around your code next time as per forum rules.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Facing 'run-time error -2147217871 (80040e31) Automation error' in excel VBA

    Where are you getting the error?

  3. #3
    Registered User
    Join Date
    09-25-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Facing 'run-time error -2147217871 (80040e31) Automation error' in excel VBA

    I am getting this error when I run the macro.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 05-15-2013, 09:02 AM
  2. Automation Error Run-time error '-2147217871 (80040e31)'
    By krishnamo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-24-2013, 02:25 PM
  3. [SOLVED] Run-time error '-2147217900(80040e14)': Automation error
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2012, 06:54 AM
  4. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  5. Run-Time Error '-21474417848 (80010108)': Automation Error
    By robotzel78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2012, 12:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1