Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all pooled connections were in use and max pool size was reached #2

Open
pedroadaodev opened this issue Feb 15, 2017 · 7 comments
Open

Comments

@pedroadaodev
Copy link

2017-02-15 16:12:45,519 DEBUG Error occurred during execution of 'Worker #4021037f' process. Execution will be retried (attempt 1 of 2147483647) in 00:00:00 seconds.
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()

In my code

using (var uow = new UnitOfWork())
{
// GET USER FROM DATABASE
var user = uow.LoginRepository.Get(email);

           // CREATE NEW ENTITY
            var entity = new FriendsEmail();
            entity.xxx = 1;
            entity.yyy = 2;

            // SAVE EMAILS
            uow.FriendsEmailRepository.Add(entity);
            uow.Commit();
        }

Any ideia?

Can it be because of this?

~UnitOfWork()
{
dispose(false);
}

why dispose(false)?

Thank you,
Pedro Adão

@alexmaris
Copy link

Can you connect to your DB at all?

The ~UnitOfWork() is the finalizer, and it should be correct in calling dispose(false).

Joe Duffy has a good writeup about dispose vs finalization: http://joeduffyblog.com/2005/04/08/dg-update-dispose-finalization-and-resource-management/

@timschreiber
Copy link
Owner

timschreiber commented Feb 15, 2017 via email

@pedroadaodev
Copy link
Author

Hi,

I can connect to the database (read and write data).

Closing my connection? Can you detail? I'm doing like this.

using (var uow = new UnitOfWork())
{
var user = uow.LoginRepository.Get(email);
}

@timschreiber
Copy link
Owner

timschreiber commented Feb 15, 2017 via email

@pedroadaodev
Copy link
Author

pedroadaodev commented Feb 15, 2017

I have change the constructor

`public UnitOfWork()
{
var connectionString = string.Empty;
connectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

        _connection = new SqlConnection(connectionString);
        _connection.Open();
        _transaction = _connection.BeginTransaction();

        _loginRepository = new LoginRepository(_transaction);

}`

@timschreiber
Copy link
Owner

timschreiber commented Feb 15, 2017 via email

@pedroadaodev
Copy link
Author

Hi,

The connection string is correct. I can read and write data on tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants