Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

c# - Am the ODBC driver of MS Access .md and .accdb files only can handle 64 executions?

Im writing a C# program where i need to use the Odbc api to connect to a .mdb database file.

After the planning, implementation and tests, now theres a BIG problem.
It seems to be, that the MS Access driver can only handles exact 64 executions.
After that, the program has to restart. Can someone confirm this issue?

Or were there other drivers, which were also more performant?

Greetings .. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

After the idea of checking the cleanups of the resources, i got the answer .. -.- :

The "using" directive from C# to handle resources had no affect on the OdbcConnection object. You have to call the Disponse method right before the next closing bracket. This closing bracket calls the Disponse method, but - I REALLY DONT KNOW WHY - this had no affect.

using (OdbcConnection conn = new OdbcConnection(string.Format(connStr, odbcDriver,
dbq, pwd)))
{
      conn.Open();
      Console.WriteLine($"Conn Create");
      await using OdbcCommand cmd = conn.CreateCommand();
      await cmd.CommandText = "select * from [testmodel];";
      cmd.Prepare();
      DbDataReader reader = cmd.ExecuteReader();
      Console.WriteLine($"DB EXEC COUNT '{i}'");
      await conn.DisposeAsync();
}

I tried out pyhons pyodbc to reproduce, that it is not a language issue .. well it worked fine..

with pyodbc.connect(f"Driver={dbAccessDriver};Dbq={dbFilePath};Pwd={dbPassword}") as conn:
            conn: pyodbc.Connection
            cmd: pyodbc.Cursor = conn.cursor()
            cmd.execute("insert into [testmodel] values (?, ?)", (i, "Name " + str(i)))
            cmd.commit()

Greetings to all programmers ..

Update 19.01.2021

Well, my last answer wasnt as correct as I expect. I thought i had solved this problem, but its not.

Actually, my last solution has based on the disposed method after the using syntax of the connection and that has to work, because the triggered Disposed event is always the same. The corrent solution is: The problem is caused by reading from a table. If reader were not closed OR disposed, this caused the error.

If you want to control the connections you have to go deeper and control read and write operations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...