Re: New to VB.NET...HELP REQUIRED IMMEDIATELY

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Scott M. (s-mar_at_nospam.nospam)
Date: 01/28/05


Date: Thu, 27 Jan 2005 19:51:17 -0500

I don't see him using one connection for 2 different commands. I see him
calling ExecuteReader on the same command twice. There is only one command
object in his code.

"W.G. Ryan eMVP" <WilliamRyan@gmail.com> wrote in message
news:OnGYw1KBFHA.3576@TK2MSFTNGP11.phx.gbl...
> Scott already answered the crux of your problem - you are using the same
> connection for two different commands which you can't do until ADO.NET 2.0
>
> But since your first execution is MAX() - then you should probably opt for
> ExecuteScalar instead of Reader. If nothing else it will save you a few
> lines of code and make your intent a little clearer.
>
> Also, you should consider using a Finally Block and closing your
> connection
> in the finally - that's the only way youy can make sure it will get
> closed.
>
> And as always - I have to include my obligatory rant against catching
> system.Exception here. Since your not doing anything with your exception
> other than writing it out - you probably ought to catch a OleDbException
> for
> the connection.Open and the Execute statements - if you got a
> StackOverflow
> or something else there - well you may want to respond differently. But
> that's another story.
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "santosh singh via DotNetMonster.com" <forum@DotNetMonster.com> wrote in
> message news:09d9cc428c6e41a4b297c987ab109eac@DotNetMonster.com...
>> Hi,
>> I'm new to VB.NET..I'm developing a login page...im getting this error..
>>
>> System.InvalidOperationException: ExecuteReader requires an open and
> available Connection. The connection's current state is Open, Fetching. at
> System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(String
> method, Int32& localState) at
> System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
> behavior, String method) at
> System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at
> System.Data.OleDb.OleDbCommand.ExecuteReader() at
> bt.index.Page_Load(Object
> sender, EventArgs e) in d:\inetpub\wwwroot\bt\index.aspx.vb:line 56
>>
>>
>> The code in .aspx.vb page is
>>
>>
>> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>> 'Put user code to initialize the page here
>> If Not IsPostBack Then
>> Try
>>
>>
>>
>> Dim MyConn As OleDbConnection = New
> OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
>> Dim strVisitor As String
>> Dim visitorCmd As OleDbCommand
>> Dim vRdr As OleDbDataReader
>> strVisitor = "select max(v_id) from visitor"
>> visitorCmd = New OleDbCommand(strVisitor, MyConn)
>> MyConn.Open()
>> Dim old_visitor As Integer
>> Dim new_visitor As Integer
>>
>> vRdr = visitorCmd.ExecuteReader()
>> While vRdr.Read()
>> If Not IsDBNull(visitorCmd.ExecuteReader()) Then
>> old_visitor = vRdr.Item(0)
>> End If
>> End While
>>
>> new_visitor = old_visitor + 1
>> lblvisitor.Text = new_visitor
>> MyConn.Close()
>>
>> Catch ex As Exception
>> Response.Write(ex)
>> End Try
>>
>> End If
>> End Sub
>>
>>
>>
>> Your help will be much appreciated
>>
>> --
>> Message posted via http://www.dotnetmonster.com
>
>



Relevant Pages

  • A VB - Datbase question
    ... causes this exception message ... Fail.ToString "System.InvalidOperationException: ExecuteReader requires an ... open and available Connection. ... behavior, String method) ...
    (microsoft.public.dotnet.languages.vb)
  • almost no asleep invasions test Roberta, and they maybe vote Sayed too
    ... disagreing in connection with the expansion's platform. ... Shah, across majors principal and lazy, commands outside it, ... Ramzi, have a blank hazard. ...
    (sci.crypt)
  • Re: Database problem.....HELP
    ... Sorry, DM, I have never used the wizard, I've always created my own connections / commands and executed them myself. ... I would suggest obtaining a valid connection string that works with this DB, then programmatically create and open a connection, create a command, add any needed parameters, etc. ... Went to add a class then seleceted SQL Database then set the name to MyCompany.mdf and clicked add, then the Data Source Configuration Wizard window opens with this error. ...
    (microsoft.public.dotnet.languages.csharp)
  • Net::SSH::Perl - Channel open failure?
    ... connecting to a host, executing commands, and displaying the results.. ... running more than one command over the same connection". ... the currently open connection (channel 0). ...
    (comp.lang.perl.misc)
  • Re: Intermittent Connection
    ... I tried Pegasus' commands but they produced an empty text file. ... Dell Inspirion Laptop, XP SP3 - MacAfee Internet Security ... It CAN be restored by unplugging / re plugging the LAN connection (to cable modem, ...
    (microsoft.public.windowsxp.general)