Connection Pool can give same connection to multiple transaction at same time? - sql-server

In the web API application, we use a repository pattern with the SQL server. we get the below connection error,
There is already an open DataReader associated with this Command
which must be closed first.
Invalid operation. The connection is
closed.
ExecuteReader requires an open and available Connection. The connection's current state is connecting.
Is there a possibility to share a connection in a connection pool?
We open multiple connections at the same time

refer below link for MARS and reused connection
https://www.designlimbo.com/multi-threading-entity-framework-and-mars/
'Because of MARS can improve performance when you have multiple concurrent operations trying to hit the database, the existing open connection is reused. '

Related

Visual Studio Server Explorer not closing sqlsrvr.exe process

I have this 'issue' since a long time and I am really wondering if this is just me or if there actually is a way of preventing the following:
UPDATED
In Visual Studio, when using the Server Explorer on a .mdf database, in a Entity Framework Code first approach project whenever I am opening the Database manually to see the data of certain tables (clicking on Show table data), it seems that even when I close the connection like this:
the database connection stays open somehow in the background.
I am getting "... the Database is currently in use ..." error if wanting to debug afterwards, after closing the connection, even when restarting the solution.
When I close all sqlservr.exe process(es) in the Task manager that does the trick.
Note that this is a local solution and a local database (.mdf) i am using for testing purposes. Nothing or no one else is using this solution.
I am quite sure this is not the behavior it should have right?
What am I doing wrong or what can I do to not have this behavior if this is not by default?
Thank you in advance for any feedback!
Include the "Pooling" flag in the connect string set to false:
Pooling=False
However, this might not be the best option in a productive environment:
Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call. (...) SQL Server Connection Pooling (ADO.NET)

Closed db connections are not released from pool

We are having dropwizard application using default configurations provided by dropwizard-jdbi for connecting to database.
Using the following to get sql connection object
Connection dbConnection = handle.getConnection();
Did a code walk-though and verified that the connections that are opened are closed.
But when i check v$session, I can see some inactive-sessions still present and are not getting released for long time.
I am using default connection pool provided by dropwizard.
Please let me know how to get the inactive sessions released.
What are your settings in the configuration file for Dropwizard?
If you have a look at http://www.dropwizard.io/1.3.0/docs/manual/configuration.html#database and then the service configuration there is an option for connections to keep alive.
# the minimum number of connections to keep open
minSize: 10
But most of the times you want to have some connections open this will speed up your application. Your application doesn't have to validate and connect to the database again and again for every call. That's one of the purposes of a connection pool.

Crystal Lang and Database Connection Pool

I have a simple code, using Kemal Crystal Framework with a database pooled connection but only mantain connection on startup, and each request decrease by one of connection to mysql.
As a DB::Database.using_connection says on docs:
yields a connection from the pool the connection is returned to the
pool when the block ends
Must not be closed !!!
https://gist.github.com/valenciaj/534b5c820462db808eac13ba6c392614
You must set max_idle_pool_size DB::Database parameter to mantain opened connections.

How many connections does an ADO connection pool contain?

As part of evaluating the load on our SQL server, I'm trying to find out how many connections can I open before ADO will open another pool.
Other than testing it empirically - can anyone has a reference to an official number/white paper on the subject?
Thanks.
Every connection pool is associated with a distinct connection string and that too, it is specific to the application. In turn, what it means is – a separate connection pool is maintained for every distinct process, app domain and connection string.
see details here: http://www.codeproject.com/KB/dotnet/ADONET_ConnectionPooling.aspx

how long must a sql server connection be idle before it is closed by the connection pool?

I have a client-server app that uses .NET SqlClient Data Provider to connect to sql server - pretty standard stuff. By default how long must connections be idle before the connection pooling manager will close the database connection and remove it from the pool? What setting if any controls this?
This MSDN document only says
The connection pooler removes a connection from the pool after it has been idle for a long time, or if the pooler detects that the connection with the server has been severed.
A few years ago the answer beneath was the situation, but now it's changed so you can refer to the source and write up a summary :)
Old answer
This excellent article tells us what we need to know, using reflection to reveal the inner workings of connection pooling.
From how I understand it, 'closed' connections are cleaned up periodically on a semi-random interval. The cleanup process runs somewhere between every 2min and 3min 50s, but it needs to run twice before a 'closed' connection will be properly closed. Therefore after 7min 40s of being 'closed' the underlying sql connection should be properly closed, but it could be as short as 2min. At the time of writing the first connection pool created in a process would always have a timer interval of 3min 10s, so you'd normally see sql connections being closed somewhere between 3min 10s and 6min 20s after you call Close() on the ADO object.
Obviously this uses undocumented code so could change in future - or could even have changed since that article was written.
Please go through this:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28VS.80%29.aspx
The part
"The following table lists the valid
names for connection pooling values
within the ConnectionString."
seems to be of your interest.

Resources