Steven M. McNeese wrote:
>
> I upgraded an old .net 2.0 application using System.Data.Sqlite v 1.0.60.0
> to .net 4.5 using system.data.sqlite v 1.0.96.0. The application started
> getting random exceptions when access the database using datsets. See
> below:
>
The only time that ObjectDisposedException will be thrown is when an attempt
is made to actually make use of a disposed object, including connections,
data readers, and commands.
For those objects, a "using" statement is typically the safest way to make
use of them, e.g.:
using (SQLiteConnection connection = new SQLiteConnection(
"Data Source=test.db;"))
{
connection.Open();
using (SQLiteCommand command = connection.CreateCommand())
{
command.CommandText = "CREATE TABLE t1(x);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO t1(x) VALUES(1);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO t1(x) VALUES(2);";
command.ExecuteNonQuery();
command.CommandText = "SELECT x FROM t1 ORDER BY x;";
using (SQLiteDataReader dataReader = command.ExecuteReader())
{
int count = 0;
while (dataReader.Read())
count++;
return count;
}
}
}
Alternatively, make sure they do not get garbage collected by keeping an
instance of them associated with another long-lived object (i.e. WinForm)
or as a static field somewhere.
--
Joe Mistachkin