ASP.Net can work with databases such as Oracle and Microsoft SQL Server.
Net to clear pool. SqlConnection. ClearAllPools() method empties the connection pool. If there are connections in use at the time of the call, they are marked appropriately and will be discarded (instead of being returned to the pool) when Close method is called on them.
Select >new Project from web option use ASP.NET empty Web Application. After loading project, select click Tools at top then select connect to Database option. Add connection dialogue box will appear click at change option and select the Microsoft SQL Server. Now enter your server name.
In most cases connection pooling problems are related to connection leaks. Your application probably doesn't close its database connections correctly and consistently. When you leave connections open, they remain blocked until the .NET garbage collector closes them for you by calling their Finalize()
method.
You want to make sure that you are really closing the connection. For example the following code will cause a connection leak, if the code between .Open
and Close
throws an exception:
var connection = new SqlConnection(connectionString);
connection.Open();
// some code
connection.Close();
The correct way would be this:
var connection = new SqlConnection(ConnectionString);
try
{
connection.Open();
someCall (connection);
}
finally
{
connection.Close();
}
or
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
someCall(connection);
}
When your function returns a connection from a class method make sure you cache it locally and call its Close
method. You'll leak a connection using this code for example:
var command = new OleDbCommand(someUpdateQuery, getConnection());
result = command.ExecuteNonQuery();
connection().Close();
The connection returned from the first call to getConnection()
is not being closed. Instead of closing your connection, this line creates a new one and tries to close it.
If you use SqlDataReader
or a OleDbDataReader
, close them. Even though closing the connection itself seems to do the trick, put in the extra effort to close your data reader objects explicitly when you use them.
This article "Why Does a Connection Pool Overflow?" from MSDN/SQL Magazine explains a lot of details and suggests some debugging strategies:
sp_who
or sp_who2
. These system stored procedures return information from the sysprocesses
system table that shows the status of and information about all working processes. Generally, you'll see one server process ID (SPID) per connection. If you named your connection by using the Application Name argument in the connection string, your working connections will be easy to find.TSQL_Replay
template to trace open connections. If you're familiar with Profiler, this method is easier than polling by using sp_who.Upon installing .NET Framework v4.6.1 our connections to a remote database immediately started timing out due to this change.
To fix simply add the parameter TransparentNetworkIPResolution
in the connection string and set it to false:
Server=myServerName;Database=myDataBase;Trusted_Connection=True;TransparentNetworkIPResolution=False
Unless your usage went up a lot, it seems unlikely that there is just a backlog of work. IMO, the most likely option is that something is using connections and not releasing them promptly. Are you sure you are using using
in all cases? Or (through whatever mechanism) releasing the connections?
Did you check for DataReaders that are not closed and response.redirects before closing the connection or a datareader. Connections stay open when you dont close them before a redirect.
We encounter this problem from time to time on our web site as well. The culprit in our case, is our stats/indexes getting out of date. This causes a previously fast running query to (eventually) become slow and time out.
Try updating statistics and/or rebuilding the indexes on the tables affected by the query and see if that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With