Crystal Lang and Database Connection Pool - database

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.

Related

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

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. '

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.

Wso2 Data Services Server timeout database connection

I have a problem in WSO2 DSS, the database connection timeout is occurring after a few hours, then I have to stopping and starting the DSS to work.
The DSS version is 2.5.1
the database server is sql server
can help me ? Thank
Have you properly configured your datasource that's used in the dataservice descriptor file to enable "validationQuery" parameter to "SELECT 1" (validation query can vary depending on the RDBMS type used but for SQL server you can use the aforementioned query) and "testOnBorrow" parameter to "true"?
To give you a bit of context on the issue, any RDBMS type by default has a connection timeout value defined. For example, MySQL has a default timeout of 8 hours by default. When connection pooling is used in an application, the connections are kept in the pool once they are created without physically closing to reuse them. However, after the aforementioned period of time, the connections become stale and you have to validate the connections before using them. This is done by specifying a validation query which will be executed whenever a pooled connection is reused. and the "testOnBorrow" parameter comes handy as, when specified, it will validate the pooled connections when they are borrowed from the conneciton pool.
Cheers,
Prabath

Connection pooling session settings

I have a small but significant query. I'll give a similiar use case but simplified, it does however cover my question.
Let's User A connects to the SQL Server 2000 database and we get a connection from the pool.
User A sets dateformat DMY. Finishes and the connections is released back to the pool.
User B comes along, connects with the same string and gets the same connection from the pool, sets the dateformat MDY, finished and returns the connection.
User A reconnects and gets the same connection, what is the dateformat ?
Is it re initialised on returning to the pool?
Do the connections retain there settings?
When the connection is removed from the pool where does a new connection take it's initial settings?
If you didn't program the pooling mechanism yourself. Its more likely that the connection goes back to its initial state before going into the pool. Moreover, there will be a configuration option where programmers can define or customize the behavior of the connection and the pool. And that is where the new connection gets its setting from. Otherwise, there must be a default settings given by the provider.

Resources