将Excel导出到多个Oracle表时发生系统错误

时间:2019-06-03 21:33:01

标签: excel vba oracle-sqldeveloper

我正在处理一个Excel文件,该文件会将其内容上载到Oracle SQL数据库。它应该能够上传到“ DEV”,“ QA”或“ PROD”数据库。我正在努力添加一项功能,该功能将同时将其添加到所有三个功能中,并遇到一些问题。 每次尝试将其运行为“全部”时,我都会不断收到系统错误:未指定的错误。我提供了下面的代码。任何帮助深表感谢!

Public Sub zUpload_Click()
Dim Environ As String

Environ = Sheets("Upload Table").Range("Environ").Value

If Environ = "DEV" Then
    xUpload (Environ)
ElseIf Environ = "QA" Then
    xUpload (Environ)
ElseIf Environ = "PROD" Then
    xUpload (Environ)
Else
    xUpload ("DEV")
    MsgBox "Upload to DEV successful"
    xUpload ("QA")
    MsgBox "Upload to QA successful"
    xUpload ("PROD")
    MsgBox "Upload to PROD successful"
End If

End Sub

代码中的下一个是:

Sub xUpload(strEnv As String)

    Dim conn As New ADODB.Connection
    Dim iRowNo As Integer
    Dim Environ As String
    Dim SrlPort As String, strHost As String, strService_Name As String
    Const IPAddr = ...This is correct...
    Const IPAddr2 = ...This is correct...
    Const IPAddr_FallBack = ...This is correct...

   Environ = Sheets("Upload Table").Range("Environ").Value

    With Sheets("Upload Table")

    Select Case Environ
    Case "QA"
        SrlPort = ...This is correct...
        strHost = ...This is correct...
        strService_Name = ...This is correct...
    Case "DEV"
        SrlPort = ...This is correct...
        strHost = ...This is correct...
        strService_Name = ...This is correct...
    Case "PROD"
        SrlPort = ...This is correct...
        strHost = ...This is correct...
        strService_Name = ...This is correct...
    End Select

        conn.Open "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" & strHost & ")(PORT=CORRECT))" _
             & "(CONNECT_DATA=(SERVICE_NAME=" & strService_Name & "))); uid=" & IPAddr & " ;pwd=" & SrlPort & ";"

这一切都在一张代码内。没有模块是什么。当我运行调试器时,它告诉我当我运行“ ALL”时conn.Open节存在问题,但我根本无法弄清。就像我说的,任何帮助都值得赞赏!

1 个答案:

答案 0 :(得分:0)

您在调用strEnv时传递了xUpload,但是忽略了它并继续从工作表范围填充Environ(尽管您没有Case "All":因此您看到的错误)

Select Case Environ

应该是

Select Case strEnv