我正在尝试让我的代码向用户询问Oracle SQL凭据。只要我将用户ID和密码写入代码,我的代码就可以正常工作,但我无法创建登录提示。显然,我宁愿不以纯文本形式存储用户ID和密码。
我相信“conn.Properties(”提示“)= adPromptAlways”这一行应该激活提示,但是我收到以下错误:
运行时错误'3220': 提供的提供者与已经使用的提供者不同。
我无法弄清楚如何修复提供程序问题,或者如何更正我的代码。关于如何解决这个问题的任何想法或来源?
Sub MySub()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim SqlText As String
Dim R As Range
Dim WS As Worksheet
Dim ws2 As Worksheet
Dim LastRow As Long, i As Long
Dim MyFileName As String
Dim WB As Workbook, TempWB As Workbook
Set WB = Workbooks("Error_cases.xlsm")
Set ws2 = WB.Sheets("Input_file")
Set WS = Sheets("Errors")
Sheets("Errors").UsedRange.ClearContents
Sheets("Input_file").UsedRange.ClearContents
' Create the connection string.
sConnString = "Provider=OraOLEDB.Oracle;Data Source=myDataSource;User Id=;Password=;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
For Each R In Sheets("SQL").Range("A1:A1")
SqlText = SqlText & R.Text
Next R
' Open the connection and execute.
conn.Properties("Prompt") = adPromptAlways
conn.Open sConnString
Set rs = conn.Execute(SqlText)
答案 0 :(得分:0)
我想出了一个解决方案,回答我自己的问题,以防其他人遇到类似的问题。显然只在连接字符串中使用提供程序导致了问题,通过在添加提示属性之前单独设置它来解决此问题
' Create the connection string.
sConnString = "Provider=OraOLEDB.Oracle;Data Source=myDataSource;
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
conn.Provider = "OraOLEDB.Oracle"
conn.Properties("Prompt") = adPromptAlways
Set rs = New ADODB.Recordset