dimanche 29 novembre 2015

C#, SQlite: Unable to open SQLite database files after opening/closing them many times

enter image description here

        public long getCntFriend()
    {
        long numOfFriend = 0;
        // Construct SQL connection
        SqliteConnectionStringBuilder connBuilder = new SqliteConnectionStringBuilder();
        connBuilder.DataSource = this.dbPath;
        connBuilder.Version = 3;
        connBuilder.JournalMode = SQLiteJournalModeEnum.Delete;
        SqliteConnection connection = new SqliteConnection(connBuilder.ToString());
        SqliteCommand cmd = new SqliteCommand(connection);
        try 
        {
            connection.Open();
            cmd.CommandText = "SELECT COUNT(*) FROM user, follow WHERE target = " + egoID + " AND source = id " +
                " AND isProtected = 0 AND followingsCount < " + followingsCountConstraint +
                " AND followersCount < " + followerCountConstraint +
                " AND tweetsCount >= " + tweetCountConstraint;
            numOfFriend = (long)cmd.ExecuteScalar();
            cmd.Dispose ();
        }
        catch (SqliteException sqlError)
        {
            Console.WriteLine(sqlError.Message);
            Environment.Exit (-1);
        }
        finally 
        {
            connection.Close();
            connection.Dispose();
            cmd.Dispose();
            connection = null;
            cmd = null;
        }

        return numOfFriend;
    }

Hello.

My C# Project needs to accesses many SQLite database files repeatedly. I have ensured following 'try', 'catch' and 'finally' procedure and closing the Sqlite DB connection properly.

One problem I encounter is that after the my C# project opens/closes database files around 120 times, SQLite gives error of "Unable to open database file". (Please see the attached screenshot file)

My environment: Mac, Xamarin Studio, C#, Mono.Sqlite

What should I do to solve the problem?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire