Reset Connection

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Microsoft SQL Server
abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Reset Connection

Post by abadia » Wed 04 Apr 2012 12:26

When we use the native connection on .NET framework (System.Data.SqlClient), by taking a connection from the pool, the connection is reseted, restoring the connection settings and deleting any temporary tables. Actually the native connection runs the stored procedure "sp_reset_connection" to do this. How do I get the same effect using dotConnect for SQL Server?

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Fri 06 Apr 2012 12:06

We will investigate the possibility to add this feature and notify you as soon as possible.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Wed 11 Jul 2012 12:10

Try using the Connection Reset parameter in your connection string. For more information, please refer to http://www.devart.com/dotconnect/sqlser ... tring.html

abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Re: Reset Connection

Post by abadia » Mon 23 Jul 2012 05:14

Sorry for the lack of clarity. I have used that parameter and it does not work. Is there anything else I should do for work?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Reset Connection

Post by Shalex » Fri 27 Jul 2012 13:57

Thank you for your report. We have reproduced the problem. We will post here when it is fixed.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Reset Connection

Post by Shalex » Wed 01 Aug 2012 13:21

sp_reset_connection is documented as an internal-use-only API system stored procedure:
http://msdn.microsoft.com/en-us/library/ms187961
http://social.msdn.microsoft.com/Forums ... 49dcfbd754
Unfortunately, there is no way to call sp_reset_connection with our provider (no support). We will correct our documentation.

abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Re: Reset Connection

Post by abadia » Thu 18 Oct 2012 14:08

I understand that and this is one of the stored procedures for internal use. Actually there is no other purpose for it in an application. It serves only to an implementation of a connection pool, which applies in this case.
There is no way to solve the problem without calling this procedure.
Currently, it is present in all versions of SQL Server at least from the 2005 version. You can create a conditional running the version of SQL Server.

The insistence on this is that its implementation is adherent to the internal pool functionality of the .net framework.

We have a development environment with a lot of legacy code, not always where temporary tables are removed at the end of use, or environment variables are returned to the previous value.

http://www.sqlmag.com/article/sql-serve ... -procedure

Please reconsider this issue. I think it's so important for us and for many other users who use the pool of connections.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Fri 19 Oct 2012 11:50

Unfortunately we can't implement the call of this function, as it's closed. If Microsoft gives access to call this function, we will implement this functionality.

abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Re: Reset Connection

Post by abadia » Fri 19 Oct 2012 13:03

Microsoft does not impose any limitation on the use of this procedure.

Actually, I managed to simulate the operation of the native connection pooling.

Of course a solution in the component itself would be much more elegant and would not provide any compatibility issue because who does not want to use just does not pass the parameter in the connection string.

Here's what I did:

Code: Select all

private SqlConnection cn = new SqlConnection();
private SqlCommand resetConnectionCmd;

public void Connect()
{
	if (cn.ConnectionString == String.Empty)
	{
		cn.ConnectionString = ConnectionString;
		cn.StateChange += (sender, e) =>
		{
			if (e.CurrentState == ConnectionState.Open)
			{
				if (resetConnectionCmd == null)
				{
					resetConnectionCmd = ((SqlConnection)sender).CreateCommand();
					resetConnectionCmd.CommandText = "sp_reset_connection";
					resetConnectionCmd.CommandType = CommandType.StoredProcedure;
				}
				resetConnectionCmd.ExecuteNonQuery();
			}
		};
	}
	cn.Open();
}

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Wed 24 Oct 2012 13:43

We will investigate the possibility to implement this functionality and notify you as soon as possible.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Wed 14 Nov 2012 11:32

We have fixed the bug with the 'Connection Reset' connection string parameter. We will post here when the corresponding build of dotConnect for SQL Server is available for download.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Thu 15 Nov 2012 15:08

The new build of dotConnect for SQL Server 2.60.615 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/sqlser ... nload.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?t=25283

abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Re: Reset Connection

Post by abadia » Thu 22 Nov 2012 12:12

I'm very happy that you made this feature. I've tested and observed the execution in my log with SQLMonitor and I have a suggestion: IMHO, since sp_resset_connection is called many times, it could be a attribute of the connection object instatiated when 'Connection Reset' parameter is "true". Thus you avoid recriation of the SQLCommand and improve speed and memory usage.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Reset Connection

Post by Pinturiccio » Fri 23 Nov 2012 11:58

If we understand you right, you want us to implement such property for the SqlConnection object that would allow you to specify explicitly whether sp_reset_connection should be performed for a specific connection instance or not.
I.e. the possibility to choose whether to run sp_reset_connection for every specific connection instance, not for all connections using this internal connection from the pool.

abadia
Posts: 16
Joined: Fri 11 May 2007 16:57

Re: Reset Connection

Post by abadia » Fri 23 Nov 2012 16:09

No. This feature is functionally perfect as is. My suggestion is just about an improvement over implementation. Since the object SQLCommand is created on each execution of the procedure, it can be cached on a private attribute (not property).

Post Reply