473,486 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SqlConnection - Reset

Is there a way of resetting the SqlConnection with closing/opening it again.
I am not seeing anything called reset.

Regards,
John
Jan 8 '07 #1
8 6781
Indirectly... since connections are often pooled, closing and opening
won't close the underlying connection, but it will force it to reset
that connection for you (to clear up any temp data etc) - which sounds
more-or-less like what you want anyway? You could perhaps run a trace
to see what (if any) SQL is issued, but this may occur under the
bonnet...

Marc
Jan 8 '07 #2
Basically that is what I want, clean up the connection... Thanks.

Regards,
John

"Marc Gravell" <ma**********@gmail.comwrote in message
news:OI*************@TK2MSFTNGP03.phx.gbl...
Indirectly... since connections are often pooled, closing and opening
won't close the underlying connection, but it will force it to reset that
connection for you (to clear up any temp data etc) - which sounds
more-or-less like what you want anyway? You could perhaps run a trace to
see what (if any) SQL is issued, but this may occur under the bonnet...

Marc

Jan 8 '07 #3
Hi Marc and John,

yes, the Open method of SqlConnection sends some reset command to the
server.
I've seen it before in the trace. I suppose, this is so, that the Connection
object can be used indepentently from any changes made in the underlying
connection, if it is a repooled connection.

Christof

"Marc Gravell" <ma**********@gmail.comschrieb im Newsbeitrag
news:OI*************@TK2MSFTNGP03.phx.gbl...
Indirectly... since connections are often pooled, closing and opening
won't close the underlying connection, but it will force it to reset that
connection for you (to clear up any temp data etc) - which sounds
more-or-less like what you want anyway? You could perhaps run a trace to
see what (if any) SQL is issued, but this may occur under the bonnet...

Marc

Jan 8 '07 #4
Basically I opened a connection and leave it open forever which normally
works fine. Before using the connection each time I checked the connection
state and if it is anything besides open I closed the connection and
reopened it.

What I would like to do assuming the connection is fetching or in error
would be to reset the connection instead of closing it.

public bool CheckConnection()
{

.... other code

switch (_Connection.State)
{
case System.Data.ConnectionState.Closed:
if (this.OnError != null)
this.OnError("Opening SQL"); ;
this._Connection.Open();
return true; ;
case System.Data.ConnectionState.Broken:
case System.Data.ConnectionState.Connecting:
case System.Data.ConnectionState.Fetching:
case System.Data.ConnectionState.Executing:
this.OnError("Closing SQL");
this._Connection.Close();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds (1));
cnt++;
break;
case System.Data.ConnectionState.Open:
return true;
}

.... error handling

return false;
}

Regards,
John
"WhiteWizard" <Wh*********@discussions.microsoft.comwrote in message
news:BC**********************************@microsof t.com...
John,

You're going to have to provide a couple more details. Like, are you
trying
to use the same parameters? Working on the database but different tables?
Can you give us a better idea of what you're trying to accomplish?

AFAIK their is no "reset" function, but you can mitigate the overhead of
recreating the SqlConnection by just closing but not disposing it between
uses.

HTH

WhiteWizard(aka Gandalf)
MCSD.NET, MCAD, MCT
"John J. Hughes II" wrote:
>Is there a way of resetting the SqlConnection with closing/opening it
again.
I am not seeing anything called reset.

Regards,
John

Jan 8 '07 #5
PS

"John J. Hughes II" <in*****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Basically I opened a connection and leave it open forever which normally
works fine. Before using the connection each time I checked the
connection state and if it is anything besides open I closed the
connection and reopened it.
You are best to close the connections when you are finished with them and
open them only if necessary. Why do you close and reopen a connection if it
is already open?

PS
>
What I would like to do assuming the connection is fetching or in error
would be to reset the connection instead of closing it.

public bool CheckConnection()
{

.... other code

switch (_Connection.State)
{
case System.Data.ConnectionState.Closed:
if (this.OnError != null)
this.OnError("Opening SQL"); ;
this._Connection.Open();
return true; ;
case System.Data.ConnectionState.Broken:
case System.Data.ConnectionState.Connecting:
case System.Data.ConnectionState.Fetching:
case System.Data.ConnectionState.Executing:
this.OnError("Closing SQL");
this._Connection.Close();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds (1));
cnt++;
break;
case System.Data.ConnectionState.Open:
return true;
}

... error handling

return false;
}

Regards,
John
"WhiteWizard" <Wh*********@discussions.microsoft.comwrote in message
news:BC**********************************@microsof t.com...
>John,

You're going to have to provide a couple more details. Like, are you
trying
to use the same parameters? Working on the database but different
tables?
Can you give us a better idea of what you're trying to accomplish?

AFAIK their is no "reset" function, but you can mitigate the overhead of
recreating the SqlConnection by just closing but not disposing it between
uses.

HTH

WhiteWizard(aka Gandalf)
MCSD.NET, MCAD, MCT
"John J. Hughes II" wrote:
>>Is there a way of resetting the SqlConnection with closing/opening it
again.
I am not seeing anything called reset.

Regards,
John

Jan 8 '07 #6
"PS" <ec***********@hotmail.comwrote in message
news:e5**************@TK2MSFTNGP06.phx.gbl...
>
"John J. Hughes II" <in*****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Basically I opened a connection and leave it open forever which normally
works fine. Before using the connection each time I checked the
connection state and if it is anything besides open I closed the
connection and reopened it.

You are best to close the connections when you are finished with them and
open them only if necessary. Why do you close and reopen a connection if
it is already open?
Two reasons. One is because of error or undisired state, it seems to be
the only way to get the connection back to the desired state. Two, which I
am not currently doing, is to save resouces on the SQL server. If I am not
going to need the connection for a while it seems better to close it, since
I am not releasing the SqlClient I am not sure if this has any affect. I am
also think this might reset the connection.
>
PS
>>
What I would like to do assuming the connection is fetching or in error
would be to reset the connection instead of closing it.

public bool CheckConnection()
{

.... other code

switch (_Connection.State)
{
case System.Data.ConnectionState.Closed:
if (this.OnError != null)
this.OnError("Opening SQL"); ;
this._Connection.Open();
return true; ;
case System.Data.ConnectionState.Broken:
case System.Data.ConnectionState.Connecting:
case System.Data.ConnectionState.Fetching:
case System.Data.ConnectionState.Executing:
this.OnError("Closing SQL");
this._Connection.Close();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds (1));
cnt++;
break;
case System.Data.ConnectionState.Open:
return true;
}

... error handling

return false;
}

Regards,
John
"WhiteWizard" <Wh*********@discussions.microsoft.comwrote in message
news:BC**********************************@microso ft.com...
>>John,

You're going to have to provide a couple more details. Like, are you
trying
to use the same parameters? Working on the database but different
tables?
Can you give us a better idea of what you're trying to accomplish?

AFAIK their is no "reset" function, but you can mitigate the overhead of
recreating the SqlConnection by just closing but not disposing it
between
uses.

HTH

WhiteWizard(aka Gandalf)
MCSD.NET, MCAD, MCT
"John J. Hughes II" wrote:

Is there a way of resetting the SqlConnection with closing/opening it
again.
I am not seeing anything called reset.

Regards,
John


Jan 9 '07 #7
Oh the profiler show exec sp_reset_connection when a connection is closed
so I am assuming that is how the correction is reset.

Regards,
John

"John J. Hughes II" <in*****@nowhere.comwrote in message
news:uR**************@TK2MSFTNGP02.phx.gbl...
Is there a way of resetting the SqlConnection with closing/opening it
again. I am not seeing anything called reset.

Regards,
John

Jan 9 '07 #8
Hi,
You are best to close the connections when you are finished with them and
open them only if necessary. Why do you close and reopen a connection if
it is already open?
Unless the OP requires pessimistic concurrency and the server and client
applications are within the same, private network or DMZ. This might also
increase performance of the application if many connections would be closed
and reopened otherwise.

--
Dave Sexton
http://davesexton.com/blog
Jan 19 '07 #9

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

Similar topics

1
558
by: Donnie Darko | last post by:
I'm trying to understand SqlConnection(), SqlCommand() For example. I use SqlConnection() as a parameter when I create a new SqlCommand. Then I open SqlConnection(), then I execute the...
4
5166
by: The Coolest Dolphin | last post by:
Hi all, I have a question/problem concerning usage of my sqlconnection throughout my program. In my main form (frmMain) I defined an sqlconnection (I've set the connection public so that I can...
17
9342
by: LP | last post by:
Hello, Here's the scenario: Object A opens a Sql Db connection to execute number of SqlCommands. Then it needs to pass this connection to a constructor of object B which in turn executes more...
1
2376
by: Mark | last post by:
I have an SqlConnection object defined as a member of main form. I also have a thread that creates an SqlDataReader but uses the same SqlConnection object. The SqlDataReader simple loops round for...
3
1749
by: Catadmin | last post by:
Hello, Everyone. I have a strange one here. I'm a DBA with relatively low program experience. Recently I was given an assignment to locate why our SQL Server has "orphaned" connections. The...
4
2043
by: Steve Richter | last post by:
I really miss c++ .... I have an SqlConnection object within my Web.UI.Page object. The thinking is that the connection to the database server is opened once when the page starts to do its...
9
4173
by: Roman | last post by:
Hello I have a component built in VB.2003. It has the following property: Public Shared mCONN As SqlConnection Public Property Connection() As SqlConnection Get Return mCONN End Get...
1
1804
by: jinfeng_Wang | last post by:
hi, I have a question about the difference between SqlConnection.IDisposable.Dispose() and SqlConnection.Dispose(). Both of them realize the function of releasing the connection to the...
4
3875
by: Victor | last post by:
Hi Guys I have a problem here. I want to improve the performance for a website. When I looked into the system, I have found that the system made the "SqlConnection Object" static. That mean only...
0
7094
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,...
0
7173
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...
1
6839
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...
0
7305
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...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.