Re: ADO Connection.Execute Method leaves Open SQL Process

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Jul 29, 3:23 pm, "Ralph" <nt_consultin...@xxxxxxxxx> wrote:
"Joe Cool" <joecool1...@xxxxxxxx> wrote in message

news:b8d8dde0-f1f1-49d3-b2cb-96dfdd073b0b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 29, 9:56 am, "Ralph" <nt_consultin...@xxxxxxxxx> wrote:

"Joe Cool" <joecool1...@xxxxxxxx> wrote in message
Definitely a multi-user app with multple boxes. What makes it
sound otherwise?

ha, your first paragraph where it talks about "a VB6 app".

but ... nvm as we are likely going into other waters... lol



Have the App create a single ADODB.Connection object (New),
then .Open and .Close it on demand, but do NOT destroy it
(Set to Nothing) until the App exits. This will insure the App is
requesting only one connection from a single ADO Connection
Pool, thus if all requests are sequenced and not over-lapping
- from the App's point of view only one connection will be ever
be requested from the Pool.
That's a very good suggestion but unfortunately would require
some major work as to the complexity of this app and my
boss is not likely to approve such a major overhaul at this time.

Then you may be screwed. <smile>

The best way to manage connections with ADO is to use the Connection Pool
and thus your first objective has to be to insure that each App uses the
Connection Pool in the most optimal manner. Period.

The connection pool is created when you create an ADODB.Connection object..
You get a pool and one connection from the pool. As long as your App makes
requests in an orderly fashion - one after another without 'over-lap'
(something in a loop, or mulitple calls to Execute in the same routine),
then the App will be able to use a single 'ADO connection' through-out its
lifetime.

Also note that an ADO Connection (not the object) is only open while it is
being used - ado connections close after 2secs to 2 minutes of inactivity
anyway. Telling the connection object to close a connection is allowing the
object to close it sooner.

Creating an destroying an ADODB.Connection adds nothing to the solution but
additional overhead.

Even after you insure this - there is likely something else going on that is
the real cause and you will have to modify your code to adapt to it.





However, SQL Server itself often creates additional "connections" to
satisfy
a request. In which case there may be little to nothing you can do about
it
from the App's side of things.

Also, if not using the return, use the adExecuteNoRecords option.

Tried that, didn't  help.



It might be useful to see your connection string and attributes, and a
sample query

Typical code:

Dim cn as Connection

With cn
    .Provider = "MSDASQL"
    .ConectionString = "User Id=username;Password-password;Data
Source=dsnname;"
    .Open
End With

' single stepping through the code and checking the SQL Activity
Monitor shows no new process created at this point!!

cn.Execute "INSERT INTO tablename ( columna ) VALUES
( 'somevalue' )", , adExecuteNoRecords

' at this point a new SQL process HAS been created!!

cn.Close
Set cn = Nothing

' SQL Process STILL exists!!

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

That is easy enough to fix.
Just create a single global reference to one ADOD.Connection object.
Run that "With cn" block once at the start of your program, then Set to
Nothing at the end. Keep the .Open - to test the connection then .Close it.
In your code before you make any connection request do a  ...
    cn.Open
        .... ' do your stuff, then ...
    cn.Close
Delete all occurances of "Set cn = Nothing".

Why? Again because after you have done that we know each App is using only
one ADO Connection. If your app is not deliberating requesting multiple
connections - then it is not ADO that is the problem.

Note: Setting a cn object to Nothing, while usually is quite deterministic
from a practical view, is not absolutely going to destroy everything at that
very sec. As ADO runs outProc - there can be an delay on a busy system,
though that is usually an exotic case.

Your real problem is most likely because SQL Server is opening up additional
implicit connections (not pooled) and holding them open - because it is
receiving multiple pending requests. Changing the Queries to SPs that don't
produce implicit default recordsets may help.

On an extremely busy system, reworking the Apps to queue messages to an
external application which does the actual communication with SQL Server may
also help to cutdown the number of actual connections.

You know, most of the time, when the connection is closed and disposed
in this VB6 app (which happens a LOT), the SQL Process in the
ActivityMonitor goes away.

But it is in this particular case, when making use of the
Connection.Execute method where it doesn't.

And what is even strnager is that the SQL Process doesn't show up the
ActivityMonitor when the connection is opend, it shows up just after
the Connection.Execute method has been invoked.

But you do make some excellent suggestions. I will pass that on, but I
am still mystified why the active SQL Process created by the
Connection.Execute method will not go away after the connection is
closed and disposed.
.



Relevant Pages

  • Re: A month with a Nokia n95 (long)
    ... and can't play. ... One of these days I will get around to writing a small app to do it all on the fly. ... HSDPA works well and you can have more than one internet connection going at once. ... For example I can use it as a modem for my laptop and also "listen again" to a Beeb radio programme. ...
    (uk.telecom.mobile)
  • Re: ADO Connection.Execute Method leaves Open SQL Process
    ... But even after the connection object is ... function of this app and it creates a new Process ID each time, ... This will insure the App is requesting only one connection from a ... ' at this point a new SQL process HAS been created!! ...
    (microsoft.public.vb.database.ado)
  • Re: ADO Connection.Execute Method leaves Open SQL Process
    ... Have the App create a single ADODB.Connection object, ... requesting only one connection from a single ADO Connection ... Pool, thus if all requests are sequenced and not over-lapping ...
    (microsoft.public.vb.database.ado)
  • Memory leak with ADO
    ... When the app runs through the loop 2k times about 16-30 megs ... procedure TForm1.SpeedButton1Click(Sender: TObject); ... Caption = 'Connection String' ... object Connection: TADOConnection ...
    (borland.public.delphi.database.ado)
  • Re: ASP.NET data access
    ... > Since you need disconnected data, datareader is not necessary. ... >> which was then saved back to the db when the app was shut down. ... >> it is returned from the dataset saving a connection, ... The problem that this technique seems to have ...
    (microsoft.public.dotnet.framework.aspnet)