作者:Life一切安好 | 来源:互联网 | 2023-07-15 17:54
我现在写了这样的函数:FunctionopenConnection()SetcnnCreateObject(ADODB.Connection)cnn.Connec
我现在写了这样的函数:
Function openConnection()
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString =
"{ORACLE ODBC DRIVER};SERVER=TEST-DB1;UID=TAOBAO;PWD=TAOBAO"
cnn.Open
If cnn.State = adStateOpen Then
cnnState = "open"
Else
cnnState = "closed"
End If
End Function
但是运行到cnn.ConnectionString =
"{ORACLE ODBC DRIVER};SERVER=TEST-DB1;UID=TAO;PWD=TAO"
这一句时程序要出错,这样的写法不对吗?请指教!
5 个解决方案
换个连接试试
"Driver={Microsoft ODBC for Oracle};SERVER=TEST-DB1;UID=TAOBAO;PWD=TAOBAO;"
www.connectionstrings.com
cOnnstr= "sysConnstr" value="Provider=OraOLEDB.Oracle.1;Data Source=db_172.18.10.11;User ID=epsys;Password=wiscom;Persist Security Info=True"
Dim cn As ADODB.Connection = New ADODB.Connection()
cn.ConnectionString = connstr
cn.Open()
Dim rs As ADODB.Recordset = New ADODB.Recordset()
Try
sql = "select f_name from rep_group where f_id='" & fid & "'"
Try
rs.Open(sql, cn)
这是偶的,测试运行了n长时间了,好好的
如果有错误的话,也可能是oledb驱动或者是mdac版本的问题,不过这些是后话
你用odbc连的啊。。那就更好说了:
Dim cn As ADODB.Connection = New ADODB.Connection()
cn.Open(dbname, dbuser, dbpwd)
'dbname是odbc数据源的名字,dbuser是用户名,dbpwd是密码。别的什么都不用写
Dim rs As ADODB.Recordset = New ADODB.Recordset()
sql = "select * from (" + sql + ") DS_linshi_ceshi where 1=2"
rs = cn.Execute(sql)