Brian Ray
9/2/2008 9:38:00 AM
Hi,
I'm trying to use OdbcConnection to connect to a database. The first time
is usually fine, but after a few times I get the following exception:
AccessViolationException - "Attempted to read or write protected memory.
This is often an indication that other memory is corrupt."
I've looked around the internet and I cannot seem to find anything remotely
helpful although there are a lot of discussions about this exception. I
would appreciate if anyone has some insight.
This is the test code I'm using (C# 2.0). On my computer, the crash usually
happens when i=3, but not always:
// START
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
OdbcConnection connection = new OdbcConnection(<connection string
omitted>)
connection.Open();
OdbcCommand command = connection.CreateCommand();
command.CommandText = "SELECT \"Date\" from \"TESTDB\".\"BIG\" group
by \"Date\"";
OdbcDataReader reader = command.ExecuteReader();
while (reader.Read())
{
}
reader.Close();
reader.Dispose();
command.Dispose();
connection.Close();
connection.Dispose();
}
// END
Thanks a lot in advance.