Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operation not allowed in this context

Status
Not open for further replies.

rennis

Programmer
Dec 6, 2006
80
CA
I get the following error on the following line of code the second time of a for loop.

IF .state = 1 then .close (basically, if the ado connection is open, then close it.)

Anyone have any idea why this happens? This line of code is used numerous times through the code but its only here that it crashes.

Any help would be greatly appreciated.
 
Can you post the relevant parts of the code where the error occurs? Just curious, why do you check for the connection state in a loop? Seems to me it would be better to open it, use it and then close but not each iteration through the loop.

I tried to have patience but it took to long! :) -DW
 
Relevant part of the code where the error occurs:
If .state = 1 then .close.

Just for stating, its vb6 with mysql backend, if it helps/makes any difference.

There are x number of items in a listview, and for each item, its information needs to be updated, hence the for loop.

Basic Code looks like the following:
For i = i to ListViewCount
If .state = 1 then .close
.open "Select a, b, c from table where pk=ItemId.
a=num1
b=num2
c=num3
.update
next i

Even modifying the code to be (close after update) makes no difference:
For i = i to ListViewCount
.open "Select a, b, c from table where pk=ItemId.
a=num1
b=num2
c=num3
.update
.close
next i

Where num1 through num3 are values in the listview.
 
<Even modifying the code to be (close after update) makes no difference>

So where does the error occur then? and what is the error?
 
It occurs on the .CLOSE in either case, and again the error is: "Operation not allowed in this context
 
It would be more usual to open the Connection object, then do your loop using the Execute method, then finally close your connection. Opening and closing a connection on a remote server in a tight loop can cause timing problems.

Do a search for Execute Method (ADO Connection) in your VBHelp for syntax details

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top