大家好
我的一个Excel VBA应用程序在Office 365上运行时遇到了一个奇怪的问题。我有一个SQL查询,它从Oracle数据库返回一些值。数据库连接是通过ODBC完成的,ODBC使用TNS文件与数据库连接。
有两个应用程序,例如App1和App2,在安装了Office 2016的开发服务器中运行良好。
当我尝试在测试服务器中运行相同的应用程序时,App1工作正常,而App2中的SQL查询没有返回任何值,即使测试数据库中有有效数据。
Code from App1 - Working as expected in both Dev & Test
DSN_ID = UCase(Sheets("Params").Range("F4").Value)
User_ID = UCase(Sheets("Params").Range("F5").Value)
Password_ID = UCase(Sheets("Params").Range("F6").Value)
DB_ID = UCase(Sheets("Params").Range("F7").Value)
'Create the connection
Set cnn1 = New ADODB.Connection
Set cmdSQL = New ADODB.Command
Dim recindex As New ADODB.Recordset
cnn1.ConnectionTimeout = 5000
cnn1.CommandTimeout = 500
With cnn1
.ConnectionString = "DSN=" & DSN_ID & ";UID=" & User_ID & _
";PWD=" & Password_ID & ";DBQ=" & DB_ID & ";ASY=OFF;"
.Open
strSQL = "SELECT Query Here"
Set recindex = cnn1.Execute(strSQL)
seqRow = 0
If Not (recindex.BOF And recindex.EOF) Then 'record(s) found
'Do something if records are found
Code from App2 - Working as expected in Dev but returning empty record set in Test
DSN_ID = UCase(Sheets("Params").Range("F4").Value)
User_ID = UCase(Sheets("Params").Range("F5").Value)
Password_ID = UCase(Sheets("Params").Range("F6").Value)
DB_ID = UCase(Sheets("Params").Range("F7").Value)
'Create the connection
Set cnn1 = New ADODB.Connection
Set cmdSQL = New ADODB.Command
Dim recindex As New ADODB.Recordset
cnn1.ConnectionTimeout = 5000
cnn1.CommandTimeout = 500
With cnn1
.ConnectionString = "DSN=" & DSN_ID & ";UID=" & User_ID & _
";PWD=" & Password_ID & ";DBQ=" & DB_ID & ";ASY=OFF;"
.Open
End With
strSQL = "SELECT Query Here"
Set recindex = cnn1.Execute(strSQL)
seqRow = 0
If Not (recindex.BOF And recindex.EOF) Then 'record(s) found
'Do something if records are found
开发环境中安装了Office 2016和64位ODBC测试环境中安装了Office 365和64位ODBC两个开发和测试应用程序都指向同一个数据库
请帮助我解决这个奇怪的问题。非常感谢。
1条答案
按热度按时间vohkndzv1#
下面是完整的函数: