Consulting

Results 1 to 8 of 8

Thread: Automation Error Run-time error '-2147217871 (80040e31)'

  1. #1

    Automation Error Run-time error '-2147217871 (80040e31)'

    Hi Guys,

    I am new to this forum. Need a little bit of help.

    I am trying to run a piece of code when i run the SQL Script it run well. But when i run the same script via VBA it throws the following error.


    ---------------------------
    Microsoft Visual Basic for Applications
    ---------------------------
    Run-time error '-2147217871 (80040e31)':

    Automation error
    ---------------------------
    OK Help
    ---------------------------
    Private Sub CommandButton4_Click()
    On Error GoTo Erred
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    ActiveSheet.DisplayPageBreaks = False
    Dim Qry As String
    Dim i As Integer
    Dim Filename As String
    Dim BkupDbname As String
    Sheet6.Db_name = "master"
    If Sheet2.cnn1.State <> adStateOpen Then
        Sheet2.connect2
    End If
    Set rs = Nothing
    If Sheet2.checkerr2 = 1 Then
        GoTo Last:
    End If
    If CheckBox1.Value = False And CheckBox2.Value = False And CheckBox2.Value = False Then
        MsgBox "Please Atleast One Checkbox!!"
        GoTo Last
    End If
    If CheckBox1.Value = True And CheckBox2.Value = True Then
        MsgBox "Please Select Only One Checkbox!!"
        GoTo Last
    End If
    If CheckBox1.Value = True And CheckBox3.Value = True Then
        MsgBox "Please Select Only One Checkbox!!"
        GoTo Last
    End If
    If CheckBox2.Value = True And CheckBox3.Value = True Then
        MsgBox "Please Select Only One Checkbox!!"
        GoTo Last
    End If
    If CheckBox1.Value = True And CheckBox2.Value = True And CheckBox3.Value = True Then
        MsgBox "Please Select Only One Checkbox!!"
        GoTo Last
    End If
    If ComboBox1.Value = "" Then
        MsgBox "Please Select the Server Name!!"
        GoTo Last
    End If
    If ComboBox2.Value = "" Then
        MsgBox "Please Select the Database Name!!"
        GoTo Last
    End If
    If ComboBox1.Value = "" And ComboBox2.Value = "" Then
        MsgBox "Please Select Server and Database Name!!"
        GoTo Last
    End If
    If CheckBox1.Value = True Then 'Back Up Only
        BkupDbname = ComboBox2.Value
        Filename = "'E\Databases\" & Application.UserName & "\" & BkupDbname & "_" & VBA.Format(Now(), "YYYY_MM_DD_HH_MM_SS") & ".bak'"
        Qry = "BACKUP DATABASE " & BkupDbname & " TO DISK = " & Filename
        MsgBox Qry
        Set Sheet6.rs = Sheet2.cnn1.Execute(Qry) 'ERROR COMES HERE
        GoTo Last
        Erred:
        MsgBox "Error occurred!! BackUp Unsuccessfull."
    End If
    Last:
    Application.ScreenUpdating = True
    Application.Calculation = True
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    End Sub
    Please help!!

    Thanks & Regards,
    Mohan Raj Krishnan
    Last edited by Aussiebear; 04-30-2023 at 05:29 AM.

  2. #2
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    what is .rs and .cnn1?

    use ADODB.Connection object to do this

  3. #3
    rs is the ADODB Recordset and cnn1 is the ADODB.connection.

  4. #4
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    can you post your workbook here?

  5. #5
    I can't paste the worksheet as it contains some confidential information. Please any other ways of help?

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Post a sample workbook with the same layout
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    HI,


    I have attached the File. The main idea is to automate the process of Backup of sql databases using excel VBA. All Databases are minimum 15GB size. When i run a back on a empty database same code works perfectly fine. Time out issue. Please help?

    Thanks & Regards,
    Mohan Raj Krishnan
    Attached Files Attached Files

  8. #8
    Hi,


    Still i am not able to find a solution for this fix. Any body had chance to look the file ?


    Thanks & Regards,
    Mohan Raj Krishnan

Posting Permissions

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