Force OleDbConnection to release the file handle

Question related to us

My code does not release the file descriptor even after I call dispose to an OleDbException thrown. Is there a way to explicitly force a program to release a file descriptor?

+3
source share
2 answers

By default, connections to the .NET database use collation . The call Close()also Dispose()simply releases the connection back to the pool; it does not actually make it close. In the end, it will exit the pool and will actually be closed.

After a little research, there seem to be two main ways that it can be predicted:

- MSDN:

, , .

:

  • , .
  • .
  • ReleaseObjectPool.
  • .

, - , , flaky . , , " " ( ).

, , , , .

+4

, Dispose(), Close() , , :

using (OleDbConnection conn = new OleDbConnection(connString))
{
    //your stuff here
    conn.Close();  //not necessary, but doesn't hurt
}

, . / .

0

Source: https://habr.com/ru/post/1746106/


All Articles