如何使用 VBscript 连接到 Oracle DB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25733257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:35:53  来源:igfitidea点击:

How to Connect to the Oracle DB using VBscript

oraclevbscript

提问by user3494938

So far I have the following code

到目前为止,我有以下代码

Dim strConnect
Dim adoConnection
Dim adoRecordset
Dim strSQL
Dim strResults
strSQL = "SELECT COUNT(distinct party_id) FROM apps.per_all_people_f"
strConnect = "Provider=OraOLEDB.Oracle.1; Password=pwd; Persist Security Info=True; User      ID=user; Data Source=source; Extended Properties="""
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Open strConnect
Set adoRecordset = CreateObject("ADODB.Recordset")
adoRecordset.ActiveConnection = adoConnection 
adoRecordset.Source = strSQL
adoRecordset.Open
Do Until adoRecordset.EOF
        strResults = adoRecordset.Fields(0).Value
        msgbox strResults
        adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Help me on correcting above code where I need to connect to Oracle DB and process some steps based on out data.

帮助我更正上述代码,其中我需要连接到 Oracle DB 并根据输出数据处理一些步骤。

Im getting following error message.

我收到以下错误消息。

Arguments are of the wrong type, are out of acceptable range, or are in conflict with another. Line 9 Source: ADODB.Connection

参数类型错误、超出可接受范围或与另一个参数冲突。第 9 行来源:ADODB.Connection

回答by Srekk

This is for your information, please correct me if I am wrong:

这是供您参考,如果我错了,请纠正我:

Ways of connecting to DB:

连接数据库的方式:

  1. Check ODBC driver is available.
  2. If yes, create DSN(System DSN) in the adminstration tools in control panel.
  3. Use the code: Set con=createobject("adodb.connection") con.open "DSN=''"
  4. Execute the query
  1. 检查 ODBC 驱动程序是否可用。
  2. 如果是,请在控制面板的管理工具中创建 DSN(系统 DSN)。
  3. 使用代码: Set con=createobject("adodb.connection") con.open "DSN=''"
  4. 执行查询


  1. Check ODBC driver is available.
  2. If not able to do DSN then Go to environmental variable and then Set Path=""
  3. Use the code: Set con=createobject("adodb.connection") or Set con=createobject("oledb.connection") con.open "Driver={Microsoft ODBC for Oracle};Server=; Uid=your_username;Pwd=your_password;"
  4. Execute Query
  1. 检查 ODBC 驱动程序是否可用。
  2. 如果不能做DSN然后转到环境变量然后设置路径=“”
  3. 使用代码: Set con=createobject("adodb.connection") 或 Set con=createobject("oledb.connection") con.open "Driver={Microsoft ODBC for Oracle};Server=; Uid=your_username;Pwd=your_password ;"
  4. 执行查询

Hope this helps. Correct me guys if I am wrong anywhere, as I am still learning.

希望这可以帮助。如果我在任何地方错了,请纠正我,因为我仍在学习。