I have an array of database servers, and want to execute the same query for all of them in a loop.
But after the first iteration the I get following error :
- Error Number: 3704
- Description: Operation is not allowed when the object is closed
The code that I've implemented is:
Dim username
Dim password
Dim serverList(4)
serverList(0) = "ServerAddress0"
serverList(1) = "ServerAddress1"
serverList(2) = "ServerAddress2"
serverList(3) = "ServerAddress3"
'username and password are properly set
for counter = 0 to UBound(serverList)-1
Set connObj = CreateObject("ADODB.Connection")
Set rsObj = CreateObject("ADODB.Recordset")
connString = ..........
connObj.Open connString, username, password
'ERROR comes here, in second iteration.
sqlScript = "SELECT * FROM ......"
rsObj.open sqlScript, connObj
Do While Not rsObj.EOF
'record set is fetched.....
rsObj.MoveNext
Loop
'current connection is closed
rsObj.close
connObj.close
Next
Note: For the first iteration this code works perfectly. Error come for second iteration.