error: an exception of type: {System.InvalidOperationException} occurred

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

I have a class - I Dim a SQLconnection, then, in Sub New, I instantiate it,
so that it's available to me whenever I reference the class (correct?):
Conn = New SqlConnection(msConn)

Then, in my Subs/Functions, this section (inherited from previous author):
If Conn.State = ConnectionState.Closed Then
Conn.ConnectionString = msConn
Conn.Open()
End If

I step through this, line by line, and Conn.Open never actually opens the
connection. I do a quick watch on 'Conn' and pretty much everything looks
right. the connection is there, the connectionstring is correct.

However - I did a quick watch on 'Conn' - - all except one thing looked
good - on the server version, it reported an error:
ServerVersion <error: an exception of type:
{System.InvalidOperationException} occurred> String

MSDN didn't help -

Any ideas on this?
 
I'm not sure I understand the issue. Is the Connection not working or are
you just curious why a property is not available at debug time?

--
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest books:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and
Hitchhiker's Guide to SQL Server 2005 Compact Edition
 
I was stepping through the code, because of an error I was getting
elsewhere - -
What I was noticing was that I could not get the Conn.Open method to
actually open the connection. I had it instantiated in the Sub New, so it
should at least be there - -
What I noticed then was the error I mentioned, as I did a quick watch - -
I would like to know what is causing the error and how to fix it, but I'd
also like to know why, when I step through the code, the Conn.Open will not
re-open the connection

The connection state is always closed.
 
What other error were you getting? Let's assume that the Connection.Open
worked. Without seeing your code, it's kinda hard to tell why the Connection
State is closed.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
ServerVersion is not accessible until the connection is open, which make
sense since you will not know the serverVersion until you have connected
to it.

But I do not know why your connection is not open without seeing your
source code.

Charles Zhang
http://www.speedydb.com
SpeedyDB ADO.NET Provider is the fastest, most secure ADO.NET provider
over Wide Area Network (WAN).
 
Back
Top