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

No Close method for AsyncConnection? #101

Closed
pcolmer opened this issue Sep 2, 2012 · 10 comments
Closed

No Close method for AsyncConnection? #101

pcolmer opened this issue Sep 2, 2012 · 10 comments
Assignees
Labels

Comments

@pcolmer
Copy link

pcolmer commented Sep 2, 2012

If I create a non-async Connection, there is a Close method I can access. However, there isn't a Close method for async connections. Should there be?

@pcolmer
Copy link
Author

pcolmer commented May 19, 2013

I've found the solution to this, and this needs to be better documented because the implication in the source is that this needs to be done when the app is suspending.

The solution is to call SQLiteConnectionPool.Shared.Reset(); This closes all of the open connections.

If I've got this wrong, perhaps the code maintainers can provide the correct solution.

Thanks,

@pcolmer pcolmer closed this as completed Jun 6, 2013
@scastria
Copy link

SQLiteConnectionPool is not public so it cannot be called!

@JanZeman
Copy link

JanZeman commented Jul 9, 2015

You can use reflection to call it. In my attempts it worked perfectly for Android and Windows, it fires back after 3x or 4x such closed connections on iOS. Damn... I was almost tempted to go for this solution but on iOS (simulator) it does not seem to be a viable solution.

There must be a reason the creators did the Reset method internal so all in all this approach is probably not recommended but I need to close the connection time to time... :-(

    private static void CloseDatabaseConnectionViaReflection()
    {
        var assembly = typeof(SQLiteAsyncConnection).GetTypeInfo().Assembly;
        var sqLiteConnectionPoolType = assembly.GetTypes().First(t => t.Name == "SQLiteConnectionPool");
        var resetMethod = sqLiteConnectionPoolType.GetMethod("Reset");

        var sqLiteConnectionPoolSharedInstance =
            sqLiteConnectionPoolType
                .GetFields(BindingFlags.Static)
                .First(field => field.IsInitOnly && field.Name == "_shared")
                .GetValue(null);

        resetMethod.Invoke(sqLiteConnectionPoolSharedInstance, null);
    }

@olumide-oyetoke
Copy link

Pls has this issue been resolved? I also need the close() method on the async connection.

@snalesso
Copy link

snalesso commented Dec 4, 2016

Up for the CloseAsync() method, and generally the missing async counterparts in the SQLiteAsyncConnection.
Why doesn't it expose an async version for all the methods provided by SQLiteConnection?
How am I supposed to commit and close the connection when using the async way?
Via SQLiteAsyncConnection.GetConnection()?

Maybe @praeclarum can easily clarify this aspect.

@praeclarum
Copy link
Owner

Yeah, this is all my fault. I still use the synchronous version so the Async version gets neglected.

I've created Issue #480 to remind me to get these back in parity.

This issue will track the change to expose SQLiteConnectionPool.Shared.Reset

@praeclarum praeclarum added the Bug label Dec 5, 2016
@praeclarum praeclarum self-assigned this Dec 5, 2016
@scionwest
Copy link

scionwest commented Dec 18, 2016

The solution is to call SQLiteConnectionPool.Shared.Reset(); This closes all of the open connections.

This issue will track the change to expose SQLiteConnectionPool.Shared.Reset

Isn't that dangerous? If you want to just close your current connection, exposing a CloseAsync method on the SQLiteAsyncConnection would be sufficient. You don't always know what other async or parallel process might have connections still being used before you just force shut them all down. I'm not sure that the pool reset needs to be exposed if CloseAsync is provided.

eric-shim pushed a commit to eric-shim/sqlite-net that referenced this issue May 24, 2017
Fix an issue that miscount length of a query including non-ascii characters

Fix praeclarum#147
Fix praeclarum#101
@praeclarum
Copy link
Owner

Working on a CloseAsync method now.

@praeclarum praeclarum reopened this Aug 5, 2017
@aphex3k
Copy link

aphex3k commented Aug 5, 2017

Thank you so much!

@uwe-neuronation
Copy link

uwe-neuronation commented Jul 23, 2018

To cleare that pool call:
SQLiteAsyncConnection.ResetPool();
im using sqlite-net-pcl 1.4.118

_connection.GetConnection().Close();
_connection.GetConnection().Dispose();
SQLiteAsyncConnection.ResetPool();

now you can establish a new connection

github-actions bot pushed a commit to Reddevildragg-UPM-Forks/sqlite-net that referenced this issue Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants