Re: ExecuteScalar closes connection

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Angel Saenz-Badillos[MS] (angelsa_at_online.microsoft.com)
Date: 07/27/04


Date: Tue, 27 Jul 2004 11:09:10 -0700

Yurcus, this should not be happening. The only reason I can think of is that
your execute command causes a very high severity exception on the server.

What version of the framework are you using? Do you have a stand alone
repro?
Thanks,

-- 
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET: http://weblogs.asp.net/angelsb/
"Yurcus" <Yurcus@discussions.microsoft.com> wrote in message
news:675E93EC-BCD6-42CD-BE04-4C444C851997@microsoft.com...
> cmd.CommandText = "SELECT count(name) FROM dbo.sysobjects " +
>                                 "WHERE xtype 'U' AND name = '" + tablename
+ "';
> int chk = Convert.ToInt32(cmd.ExecuteScalar());
> if(outDBConnection.State == ConnectionState.Closed)
>              outDBConnection.Open();
>
> Sometimes after executing cmd.ExecuteScalar the connection is closed,
sometimes it is not and i cannot come up with a rule of why it happens so i
just check it every time and reopen my connection is nessesary.
> cmd and oudDBConnections are declared as IDBCommand and IDBConnection
because my program must be able to connect to Oracle MSDE or Access.
> In this case my variables are instantiated with SQLConnection and
SQLCommand.
>
> Thanks
>
> "Miha Markic [MVP C#]" wrote:
>
> > Hi Yurcus,
> >
> > What do you mean by closes the connections?
> > The SqlConnection or physicall connection?
> > Can you show us a piece of the code?
> >
> > -- 
> > Miha Markic [MVP C#] - RightHand .NET consulting & development
> > miha at rthand com
> > www.rthand.com
> >
> > "Yurcus" <Yurcus@discussions.microsoft.com> wrote in message
> > news:B2E98E1B-71D6-4C9E-9D2A-898DBF94E26B@microsoft.com...
> > > Hi,
> > > I have noticed that sometimes ExecuteScalar closes underlying
connection.
> > > My command object is delared as IDBCommand but instansiated with
> > SQLCommand. I am connecting to MSDE2000.
> > > My ExecuteScalar is called in the initialization of my app so all
> > conditions (such as usage history) are supposed to be same but sometimes
it
> > closes my connection, sometimes not.
> > > Has anyone encountered the same problem? Anyone can explain this or
this
> > is a bug??
> > > have fun:)
> >
> >
> >


Relevant Pages

  • RE: ExecuteScalar closes connection
    ... IDBCommand.executescalar is used for fastest retrieval so it can try to close database connection sometimes. ... MCP - ASP.NET ... "Yurcus" wrote: ... > My ExecuteScalar is called in the initialization of my app so all conditions are supposed to be same but sometimes it closes my connection, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: .NET 2.0 und Oracle
    ... einzigen Kunden das ... zwar ein ExecuteScalar auf einer Oracle-Verbindung. ... Die Datenbank ist eine Oracle 10g, der Rechner, auf dem die ... Connection und des SQL-Statements... ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • RE: Need to return a string ( varchar(40) ) from MS-SQLSERVER stored p
    ... must close the connection before the values of output parameters are ... ExecuteNonQuery, ExecuteScalar, etc. and I just can't get the value. ... keeping the empty string in the 4th parameter: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Best practice to work with multiple DB connections
    ... Thanks for your valuable input. ... "Marc Gravell" wrote in message ... call ExecuteScalar -on the same connection - while ExecuteReader is in progress. ... When you Closea managed connection it simply goes back into the pool. ...
    (microsoft.public.dotnet.languages.csharp)