Solved

Error "The connection cannot be used to perform this operation. It is either closed or invalid in this context."

Posted on 2007-11-15
4
1,321 Views
Last Modified: 2008-02-01
ERROR "The connection cannot be used to perform this operation. It is either closed or invalid in this context.".  

==================CODE====================================

            rs = New ADODB.Recordset
            rs.CursorLocation = rs.CursorLocation.adUseClient
            rs.CursorType = rs.CursorType.adOpenForwardOnly
            If intMaxRecords > 0 Then
                rs.MaxRecords = intMaxRecords
            End If
            rs.StayInSync = False
            rs.Open(strSQL, vConn.mDBConn, ADODB.CursorTypeEnum.adOpenStatic, rs.LockType.adLockOptimistic)

===============================================================================


The VS.Net is giving me error at the last line.  I have open the connection using ADODB interface.

I do not know what is happening.  Please help
0
Comment
Question by:tgatif
4 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20296327
make sure vConn.mDBConn has been defined correctly and is not busy with some other result set before this point.  try vConn.mDBConn.Open before the block you pasted
0
 
LVL 5

Expert Comment

by:pavaneeshkumar
ID: 20296627
Check the Stat property before opening reord set
Record set oopening will work only if Stat is eqa;s to ConnectionState.Open

0
 
LVL 4

Expert Comment

by:JunnickYso
ID: 20296851
One of the factor of this problem is a concurrent connection attempt. Either a current connection is still open. Im not quite familiar with RecordSets but the code stated might be under LOOP block the error will occur. Anyway check also ur strSQL variable, and nothing wrong with double check it.

Good Luck
0
 
LVL 8

Expert Comment

by:Autoeforms
ID: 20297735
how long are you keeping your connection open.
is your app off doing something else.
depending on your back end it may have terminated the connection because it was idle to long.
g
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question