473,624 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server connection pooling

I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first." , I
understand that I want to release/close connections in a timely fashion.
What I do is I declare the SqlClient.SqlCo nnection variable as a local
variable inside my subroutine (instead of a global variable). Right before I
Fill the dataset I open the connection, and right after I fill the dataset I
close the connection, like shown below. Do I do it correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCom mand = m_cmdSQL
daSQL.Fill(m_ds SQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close() '--close connection
adoCon = Nothing
End If

May 16 '07 #1
9 4754
I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so you
don't have to close a DataReader (or whatever) first to be able to go for
the next one.

see this link with information about it:

http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******** *****@TK2MSFTNG P05.phx.gbl...
>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first." ,
I understand that I want to release/close connections in a timely fashion.
What I do is I declare the SqlClient.SqlCo nnection variable as a local
variable inside my subroutine (instead of a global variable). Right before
I Fill the dataset I open the connection, and right after I fill the
dataset I close the connection, like shown below. Do I do it correctly ?
Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCom mand = m_cmdSQL
daSQL.Fill(m_ds SQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close() '--close connection
adoCon = Nothing
End If

May 16 '07 #2
Thank you.
Does it mean that if I set MultipleActiveR esultSets to true, I can have more
than 1 DataReader open in the connection ?

Regarding using a local SQLConnection variable (instead of using a global
one) and set it to new, open and close the connection everytime I fill a
dataset, is it correct ?
Or, do I need to use a global SQLConnection variable
1. new and open it on form_load (and do not close this one until
form_Closed)
2. and in each subroutine use this global SQLConnection variable but new,
open and close the connection in this subroutine ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******** ******@TK2MSFTN GP06.phx.gbl...
>I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so you
don't have to close a DataReader (or whatever) first to be able to go for
the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******** *****@TK2MSFTNG P05.phx.gbl...
>>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first." ,
I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable as a
local variable inside my subroutine (instead of a global variable). Right
before I Fill the dataset I open the connection, and right after I fill
the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCo mmand = m_cmdSQL
daSQL.Fill(m_d sSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close () '--close connection
adoCon = Nothing
End If


May 16 '07 #3
Also, when I set my connection string to the following
Data Source=mySQL200 5;Initial Catalog=myDB;Us er
ID=myUserID;Pas sword=myPass;Mu ltipleActiveRes ultSets=True
I got the error "Keyword not supported: 'multipleactive resultsets'.

Dim adoCon As SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path -->>error here
.Open()
End With

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******** ******@TK2MSFTN GP06.phx.gbl...
>I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so you
don't have to close a DataReader (or whatever) first to be able to go for
the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******** *****@TK2MSFTNG P05.phx.gbl...
>>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first." ,
I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable as a
local variable inside my subroutine (instead of a global variable). Right
before I Fill the dataset I open the connection, and right after I fill
the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCo mmand = m_cmdSQL
daSQL.Fill(m_d sSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close () '--close connection
adoCon = Nothing
End If


May 16 '07 #4
Regarding MultipleActiveR esultSets, that's right, set it to True and your
may be able to have more than a DataReader open at the same time, just
remember to close them anyway so the system behaves nicely with resources
like memory usage, processor, network and so on.

Regarding the issue of using a local or global connection, it will depend on
your application, but if the application is moderate or intensive in its use
of database, then I will recomend to use a global connection.

You may want to take a look at the Database Application Block from the
Microsoft Enterprise Library 3.0 (it's free -$0.00- !!!). It makes things a
little bit easier to access the database and you don't have to control the
connection state yourself (it handles the connection state, a connection
pool, and so on):

http://msdn2.microsoft.com/en-us/library/aa480453.aspx

Hope this helps,

Carlos Camargo
"fniles" <fn****@pfmail. comescribió en el mensaje
news:uF******** ********@TK2MSF TNGP06.phx.gbl. ..
Thank you.
Does it mean that if I set MultipleActiveR esultSets to true, I can have
more than 1 DataReader open in the connection ?

Regarding using a local SQLConnection variable (instead of using a global
one) and set it to new, open and close the connection everytime I fill a
dataset, is it correct ?
Or, do I need to use a global SQLConnection variable
1. new and open it on form_load (and do not close this one until
form_Closed)
2. and in each subroutine use this global SQLConnection variable but new,
open and close the connection in this subroutine ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******** ******@TK2MSFTN GP06.phx.gbl...
>>I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so you
don't have to close a DataReader (or whatever) first to be able to go for
the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******* ******@TK2MSFTN GP05.phx.gbl...
>>>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first."
, I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable as
a local variable inside my subroutine (instead of a global variable).
Right before I Fill the dataset I open the connection, and right after I
fill the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectC ommand = m_cmdSQL
daSQL.Fill(m_ dsSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close( ) '--close connection
adoCon = Nothing
End If



May 16 '07 #5
Thank you.
If I use a global variable, does it mean that
1. I set it to new and open it on main form_load (and do not close this one
until form_Closed)
2. and in each subroutine use this global SQLConnection variable but set it
to new, open and close this connection in this subroutine ?
or,
simply in each subroutine use this global SQLConnection variable but set it
to new, open and close this connection in this subroutine, and do not need
to open it in the main form_load ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Regarding MultipleActiveR esultSets, that's right, set it to True and your
may be able to have more than a DataReader open at the same time, just
remember to close them anyway so the system behaves nicely with resources
like memory usage, processor, network and so on.

Regarding the issue of using a local or global connection, it will depend
on your application, but if the application is moderate or intensive in
its use of database, then I will recomend to use a global connection.

You may want to take a look at the Database Application Block from the
Microsoft Enterprise Library 3.0 (it's free -$0.00- !!!). It makes things
a little bit easier to access the database and you don't have to control
the connection state yourself (it handles the connection state, a
connection pool, and so on):

http://msdn2.microsoft.com/en-us/library/aa480453.aspx

Hope this helps,

Carlos Camargo
"fniles" <fn****@pfmail. comescribió en el mensaje
news:uF******** ********@TK2MSF TNGP06.phx.gbl. ..
>Thank you.
Does it mean that if I set MultipleActiveR esultSets to true, I can have
more than 1 DataReader open in the connection ?

Regarding using a local SQLConnection variable (instead of using a global
one) and set it to new, open and close the connection everytime I fill a
dataset, is it correct ?
Or, do I need to use a global SQLConnection variable
1. new and open it on form_load (and do not close this one until
form_Closed)
2. and in each subroutine use this global SQLConnection variable but new,
open and close the connection in this subroutine ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******* *******@TK2MSFT NGP06.phx.gbl.. .
>>>I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so
you don't have to close a DataReader (or whatever) first to be able to
go for the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy****** *******@TK2MSFT NGP05.phx.gbl.. .
I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first."
, I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable as
a local variable inside my subroutine (instead of a global variable).
Right before I Fill the dataset I open the connection, and right after
I fill the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.Select Command = m_cmdSQL
daSQL.Fill(m _dsSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close () '--close connection
adoCon = Nothing
End If





May 16 '07 #6
fniles,

MARS is a .Net 2 feature. You would need to use VS 2005 to have access to it.

I will also mention that using MARS is more involved than just turning it on
in the connection string. MARS has all sorts of ramifications that you need
to understand really well before using it.

Kerry Moorman
"fniles" wrote:
Also, when I set my connection string to the following
Data Source=mySQL200 5;Initial Catalog=myDB;Us er
ID=myUserID;Pas sword=myPass;Mu ltipleActiveRes ultSets=True
I got the error "Keyword not supported: 'multipleactive resultsets'.

Dim adoCon As SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path -->>error here
.Open()
End With

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******** ******@TK2MSFTN GP06.phx.gbl...
I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so you
don't have to close a DataReader (or whatever) first to be able to go for
the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******** *****@TK2MSFTNG P05.phx.gbl...
>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an open
DataReader associated with this Connection which must be closed first." ,
I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable as a
local variable inside my subroutine (instead of a global variable). Right
before I Fill the dataset I open the connection, and right after I fill
the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCom mand = m_cmdSQL
daSQL.Fill(m_ds SQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close() '--close connection
adoCon = Nothing
End If


May 16 '07 #7
Open the connection in your application's entry point, for example in the
Load event for the main form, and store the resulting connection object in a
global variable.

Close it when that same form gets closed.

In individual procedures where you go for some info from the database or
update data there, just send the querys and get the results, don't open the
connection and close it again, because doing that (open and close
connections all the time) will make your application somehow slow because
opening the connection involves a relatively-heavy process for both, the
server computer and the client computer. Once a connection gets stablished
things will go faster.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:ew******** ******@TK2MSFTN GP03.phx.gbl...
Thank you.
If I use a global variable, does it mean that
1. I set it to new and open it on main form_load (and do not close this
one until form_Closed)
2. and in each subroutine use this global SQLConnection variable but set
it to new, open and close this connection in this subroutine ?
or,
simply in each subroutine use this global SQLConnection variable but set
it to new, open and close this connection in this subroutine, and do not
need to open it in the main form_load ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>Regarding MultipleActiveR esultSets, that's right, set it to True and your
may be able to have more than a DataReader open at the same time, just
remember to close them anyway so the system behaves nicely with resources
like memory usage, processor, network and so on.

Regarding the issue of using a local or global connection, it will depend
on your application, but if the application is moderate or intensive in
its use of database, then I will recomend to use a global connection.

You may want to take a look at the Database Application Block from the
Microsoft Enterprise Library 3.0 (it's free -$0.00- !!!). It makes things
a little bit easier to access the database and you don't have to control
the connection state yourself (it handles the connection state, a
connection pool, and so on):

http://msdn2.microsoft.com/en-us/library/aa480453.aspx

Hope this helps,

Carlos Camargo
"fniles" <fn****@pfmail. comescribió en el mensaje
news:uF******* *********@TK2MS FTNGP06.phx.gbl ...
>>Thank you.
Does it mean that if I set MultipleActiveR esultSets to true, I can have
more than 1 DataReader open in the connection ?

Regarding using a local SQLConnection variable (instead of using a
global one) and set it to new, open and close the connection everytime I
fill a dataset, is it correct ?
Or, do I need to use a global SQLConnection variable
1. new and open it on form_load (and do not close this one until
form_Closed )
2. and in each subroutine use this global SQLConnection variable but
new, open and close the connection in this subroutine ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um****** ********@TK2MSF TNGP06.phx.gbl. ..
I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so
you don't have to close a DataReader (or whatever) first to be able to
go for the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy***** ********@TK2MSF TNGP05.phx.gbl. ..
>I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an
open DataReader associated with this Connection which must be closed
first." , I understand that I want to release/close connections in a
timely fashion. What I do is I declare the SqlClient.SqlCo nnection
variable as a local variable inside my subroutine (instead of a global
variable) . Right before I Fill the dataset I open the connection, and
right after I fill the dataset I close the connection, like shown
below. Do I do it correctly ? Thank you.
>
sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter
>
adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.Selec tCommand = m_cmdSQL
daSQL.Fill( m_dsSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Clos e() '--close connection
adoCon = Nothing
End If
>
>
>




May 16 '07 #8
I am using VB.NET 2003, so MultipleActiveR esultSets is not available (it's
available in 2005 according to another user here).
In the individual procedures if I do not open and close the connection, I
will get the error "There is already an open DataReader associated with this
Connection which must be closed first."
You mentioned that if I open and close the connection the application will
be slow, but I thought with connection pooling this won't be slow, am I
wrong ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:Oc******** ******@TK2MSFTN GP05.phx.gbl...
Open the connection in your application's entry point, for example in the
Load event for the main form, and store the resulting connection object in
a global variable.

Close it when that same form gets closed.

In individual procedures where you go for some info from the database or
update data there, just send the querys and get the results, don't open
the connection and close it again, because doing that (open and close
connections all the time) will make your application somehow slow because
opening the connection involves a relatively-heavy process for both, the
server computer and the client computer. Once a connection gets stablished
things will go faster.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:ew******** ******@TK2MSFTN GP03.phx.gbl...
>Thank you.
If I use a global variable, does it mean that
1. I set it to new and open it on main form_load (and do not close this
one until form_Closed)
2. and in each subroutine use this global SQLConnection variable but set
it to new, open and close this connection in this subroutine ?
or,
simply in each subroutine use this global SQLConnection variable but set
it to new, open and close this connection in this subroutine, and do not
need to open it in the main form_load ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:%2******* *********@TK2MS FTNGP03.phx.gbl ...
>>Regarding MultipleActiveR esultSets, that's right, set it to True and
your may be able to have more than a DataReader open at the same time,
just remember to close them anyway so the system behaves nicely with
resources like memory usage, processor, network and so on.

Regarding the issue of using a local or global connection, it will
depend on your application, but if the application is moderate or
intensive in its use of database, then I will recomend to use a global
connection.

You may want to take a look at the Database Application Block from the
Microsoft Enterprise Library 3.0 (it's free -$0.00- !!!). It makes
things a little bit easier to access the database and you don't have to
control the connection state yourself (it handles the connection state,
a connection pool, and so on):

http://msdn2.microsoft.com/en-us/library/aa480453.aspx

Hope this helps,

Carlos Camargo
"fniles" <fn****@pfmail. comescribió en el mensaje
news:uF****** **********@TK2M SFTNGP06.phx.gb l...
Thank you.
Does it mean that if I set MultipleActiveR esultSets to true, I can have
more than 1 DataReader open in the connection ?

Regarding using a local SQLConnection variable (instead of using a
global one) and set it to new, open and close the connection everytime
I fill a dataset, is it correct ?
Or, do I need to use a global SQLConnection variable
1. new and open it on form_load (and do not close this one until
form_Close d)
2. and in each subroutine use this global SQLConnection variable but
new, open and close the connection in this subroutine ?

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um***** *********@TK2MS FTNGP06.phx.gbl ...
>I get the same message a couple of weeks ago.
>
You can use the MultipleActiveR esultSets on your connection string so
you don't have to close a DataReader (or whatever) first to be able to
go for the next one.
>
see this link with information about it:
>
>
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx
>
Hope it helps.
>
Best regards,
>
Carlos Camargo
>
"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy**** *********@TK2MS FTNGP05.phx.gbl ...
>>I am using VB.NET 2003 and SQL 2005.
>To use connection pooling and avoid the error "There is already an
>open DataReader associated with this Connection which must be closed
>first." , I understand that I want to release/close connections in a
>timely fashion. What I do is I declare the SqlClient.SqlCo nnection
>variable as a local variable inside my subroutine (instead of a
>global variable). Right before I Fill the dataset I open the
>connection , and right after I fill the dataset I close the
>connection , like shown below. Do I do it correctly ? Thank you.
>>
>sub MySub
>Dim adoCon As SqlClient.SqlCo nnection
>Dim cmdSQL As SqlClient.SqlCo mmand
>Dim dsSQL As DataSet
>Dim daSQL As SqlClient.SqlDa taAdapter
>>
>adoCon = New SqlClient.SqlCo nnection
>With adoCon
> .ConnectionStri ng = DB_Path
> .Open() '--open connection
>End With
>cmdSQL = New SqlClient.SqlCo mmand
>With cmdSQL
> .Connection = adoCon
> .CommandText = sSQL
>End With
>daSQL = New SqlClient.SqlDa taAdapter
>dsSQL = New DataSet
>daSQL.Sele ctCommand = m_cmdSQL
>daSQL.Fill (m_dsSQL) '--fill dataset
>If Not adoCon Is Nothing Then
>adoCon.Clo se() '--close connection
>adoCon = Nothing
>End If
>>
>>
>>
>
>




May 16 '07 #9
Thanks Kerry,
For awhile there I thought that there was no rational people lurking on
this list.
I completely agree. Use MARS at your own risk. It is fraught with issues and
unintended side-effects. While it might mask the issue of an unclosed
operation on a connection, it simply delays the inevitable.
The ultimate solution to the problem is understanding how the
instantiation and tear-down of Connections works. You simply must close
connections when they are in scope--you can't depend on the finalizer or
garbage collector to do so.

--
_______________ _______________ ______
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)
-----------------------------------------------------------------------------------------------------------------------

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.comwrote in message
news:A5******** *************** ***********@mic rosoft.com...
fniles,

MARS is a .Net 2 feature. You would need to use VS 2005 to have access to
it.

I will also mention that using MARS is more involved than just turning it
on
in the connection string. MARS has all sorts of ramifications that you
need
to understand really well before using it.

Kerry Moorman
"fniles" wrote:
>Also, when I set my connection string to the following
Data Source=mySQL200 5;Initial Catalog=myDB;Us er
ID=myUserID;Pa ssword=myPass;M ultipleActiveRe sultSets=True
I got the error "Keyword not supported: 'multipleactive resultsets'.

Dim adoCon As SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path -->>error here
.Open()
End With

"Carlos Camargo" <cc******@INVAL ID.yahoo.comwro te in message
news:um******* *******@TK2MSFT NGP06.phx.gbl.. .
>I get the same message a couple of weeks ago.

You can use the MultipleActiveR esultSets on your connection string so
you
don't have to close a DataReader (or whatever) first to be able to go
for
the next one.

see this link with information about it:
http://msdn2.microsoft.com/en-us/lib...esultsets.aspx

Hope it helps.

Best regards,

Carlos Camargo

"fniles" <fn****@pfmail. comescribió en el mensaje
news:uy******** *****@TK2MSFTNG P05.phx.gbl...
I am using VB.NET 2003 and SQL 2005.
To use connection pooling and avoid the error "There is already an
open
DataReader associated with this Connection which must be closed
first." ,
I understand that I want to release/close connections in a timely
fashion. What I do is I declare the SqlClient.SqlCo nnection variable
as a
local variable inside my subroutine (instead of a global variable).
Right
before I Fill the dataset I open the connection, and right after I
fill
the dataset I close the connection, like shown below. Do I do it
correctly ? Thank you.

sub MySub
Dim adoCon As SqlClient.SqlCo nnection
Dim cmdSQL As SqlClient.SqlCo mmand
Dim dsSQL As DataSet
Dim daSQL As SqlClient.SqlDa taAdapter

adoCon = New SqlClient.SqlCo nnection
With adoCon
.ConnectionStri ng = DB_Path
.Open() '--open connection
End With
cmdSQL = New SqlClient.SqlCo mmand
With cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
daSQL = New SqlClient.SqlDa taAdapter
dsSQL = New DataSet
daSQL.SelectCo mmand = m_cmdSQL
daSQL.Fill(m_d sSQL) '--fill dataset
If Not adoCon Is Nothing Then
adoCon.Close () '--close connection
adoCon = Nothing
End If





May 16 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2522
by: Florin | last post by:
Hi, I am experiencing some problems accessing an Oracle database through OLE DB from an MTS application using OpenWithServiceComponents (which is supposed to give me connection pooling). When I connect to a SQL Server database it only takes 3.1 ms to open a connection, while with Oracle it takes 15.5 ms (both DB's running on the same machine). Am I doing something wrong, am I missing something here? I have tried to use the plain Open...
1
3468
by: rob | last post by:
Hello, Newbie of sorts. Been reading up on best practices though. I'm trying to optimize performance to the SQL DB vs. the Web server and an ASP application. I've read that you're supposed to open late/close early which makes sense. In the past I'd created a connection and thrown many queries against the same connection. Now, I'm working with a recordset object which is returned and the ActiveConnection is closed after each query. My...
6
3787
by: Mark | last post by:
Where is the connection pooling done when using ADO.NET and SQL Server? On the SQL Server or where the .NET run-time is being executed? I'm assuming on SQL Server as this would minimize the number of connections needed in the pool. Thanks in advance. Mark
1
1075
by: Vb2Machines | last post by:
Hello, I am in the process of building a web service that will connect to my sql server for data retrieval only. It will have to handle requests from multiple apps on our shop floor. Roughly 5 queries per application every 10 seconds. There is approximately 30 apps. It will be returning an object that holds an int and a string. My question is: Should I open then sqlconnection when the web service starts and close it
6
2554
by: John J. Hughes II | last post by:
I have an application that connects to an SQL server. I need to be able to disconnect all connection that I opened. I am closing and disposing the connection but the connection pool is keeping them alive for later use. How do I convince the connection pool to drop the connections without closing my program. Regards, John
1
5716
by: Lenny Shprekher | last post by:
Hi, I am getting issues that Oracle collecting opened sessions (connections) from my webservice using regular System.Data.OleDb.OleDbConnection object. I am guessing that this is connection pooling issue. Is there is any way to disable connection pooling for one particular .net webservice? Thanks, Leonid
7
2200
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
0
6597
viswarajan
by: viswarajan | last post by:
Introduction This article is to go in deep in dome key features in the ADO.NET 2 which was shipped with VS 2005. In this article I will go trough one of the key features which is the Connection Pooling. This feature is a key feature plays an important role in the performance in most of business application or Data driven application. What's Connection Pooling?
3
3093
by: =?Utf-8?B?QXho?= | last post by:
Is there a limitation on the number of (sequential) opened connection for SQL Server User Instances? The following method will run to about the 240th iteration then will receive a timeout exception (SqlException. "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."). If User Instance=false then the method will execute to completion. Note that connection pooling is off just...
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.