vba 如何在 Oracle ODBC 连接字符串中指定“服务名称”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26848486/
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
How to specify "Service Name" in Oracle ODBC connection string
提问by Ned
I have an Excel macro that has an Oracle database connection. When I call the macro, it fills out user name and password but not service name. User has to enter service name manually every time.
我有一个具有 Oracle 数据库连接的 Excel 宏。当我调用宏时,它填写用户名和密码,但不填写服务名称。用户每次都必须手动输入服务名称。
How can I specify it in the connection string?
如何在连接字符串中指定它?
Connection string:
连接字符串:
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;DB=" & inputHost & ";" & _
"DefaultIsolationLevel=READUNCOMMITTED"
Excel prompt:
Excel提示:
回答by Ned
Found it. It's DBQ
找到了。这是DBQ
New connection string:
新连接字符串:
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"DBQ=" & inputHost & ";UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;DB=" & inputHost & ";" & _
"DefaultIsolationLevel=READUNCOMMITTED"
回答by Jimmy Smith
It depends on your driver, check this out
这取决于你的司机,看看这个
But without a config file, you have to specify the options in the connection string. Give this a try,
但是没有配置文件,您必须在连接字符串中指定选项。试试这个,
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Oracle in OraClient11g_home2};" & _
"SERVICE_NAME=" & inputHost & ";UID=" & inputUser & ";PWD=" & inputPassword & ";" & _
"HOST=" & inputHost & ";PORT=1521;" & _
"DefaultIsolationLevel=READUNCOMMITTED"
Also, make sure inputHost should be used in both cases where it is currently. One should be an instance of a server with the other being the database within it.
此外,请确保 inputHost 应在当前使用的两种情况下使用。一个应该是服务器的一个实例,另一个是其中的数据库。