Skip to content

System.ObjectDisposedException: 'Cannot access a disposed object. Object name: 'SQLiteConnection'.' #5

@dchubad

Description

@dchubad

I created a simple form with a button, when clicked will run a function called populate(). using the chunk of code below causes an error as in the title of this post.

        private void Populate()
        {
            var countStatementBuilder = new CountStatementBuilder();
            countStatementBuilder.CommandText("SELECT COUNT(*) FROM dbMyBirds");

            var rowsStatementBuilder = new RowsStatementBuilder();
            rowsStatementBuilder.CommandText("SELECT * FROM dbMyBirds LIMIT {1} OFFSET {2}");

            dataGridViewPaging1.DbRequestHandler = new DbRequestHandler
            {
                Connection = new SQLiteConnection("Data Source=dbMyBirds.sqlite3"),
                CountStatementBuilder = countStatementBuilder,
                RowsStatementBuilder = rowsStatementBuilder
            };
        }

The first time I click the button it will populate the datagridview, the 2nd time I get an Exception Unhandled
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'SQLiteConnection'.'

The only changes I made was pointing it to my db file and db name.

Edit:
I was hoping to be able to implement some search features such as searching by various columns, keywords, return limited search results... thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions