faizanjehangir
faizanjehangir

Reputation: 2851

sqlite c#: database connection not valid

I have a sqlite database file in .s3db, It has all the tables and data already populated in it. I am trying to connect to to the database use sqliteConnection. But it does not seem to work..I have added the reference of sqlite.dll, does c# needs some other reference to make the connection? If I make a new sqlite db, it is made as xyz.sqlite, maybe it is not recognizing the database extension.

This is how I am making the connection:

// Creates a connection with our database file.
        public void connectToDatabase()
        {
            //this.dbConnection = new SQLiteConnection(@"data source=Fut_Autobuyer_2012.s3db;version=3;");
            string dbConnectionString = @"Data Source=Fut_Autobuyer_2012.s3db";
            this.dbConnection = new SQLiteConnection(dbConnectionString);
        }

This is what I get when the connection is made:

Database connection not valid for getting number of changes.
Database connection not valid for getting last insert rowid.
Database connection not valid for getting maximum memory used.
Database connection not valid for getting memory used.

Upvotes: 0

Views: 2566

Answers (1)

Alexey
Alexey

Reputation: 1904

It looks like you must open database connection:

using (var connection = SQLiteFactory.Instance.CreateConnection())
{
  Debug.Assert(connection != null, "connection != null");
  connection.ConnectionString = connectionString;
  connection.Open();

  try
  {
    using (var command = connection.CreateCommand())
    {
      // Execute connection
    }
  }
  finally
  {
    connection.Close();
  }
}

Upvotes: 6

Related Questions