Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OledbConnection.Dispose() close the connection? [duplicate]

Possible Duplicate:
Is there any need to close a DbConnection if a using clause is used?

Does OledbConnection.Dispose() close the connection?

I am aware that SqlConnection does but what about OledbConnection?

like image 950
CJ7 Avatar asked Aug 20 '12 08:08

CJ7


People also ask

Does SqlConnection dispose close connection?

If the SqlConnection goes out of scope, it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose . Close and Dispose are functionally equivalent. If the connection pooling value Pooling is set to true or yes , the underlying connection is returned back to the connection pool.

How do you cancel OleDbConnection?

You should make use of the using block which will ensure the connection is closed and disposed correctly. using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection. Open(); //Do some work }//The connection is automatically closed when the code exits the using block.

What method inside the OleDbConnection needs to execute to have a connection to the database?

The OleDbConnection is opened and set as the Connection for the OleDbCommand. The example then calls ExecuteNonQuery and closes the connection. To accomplish this, ExecuteNonQuery is passed a connection string and a query string that is an SQL INSERT statement.

What is the correct form of OleDbConnection syntax?

OleDbConnection("Provider = Microsoft. Jet. OLEDB. 4.0; Data Source = '\\csvFile.


1 Answers

Yes, it also does.

Source: OleDbConnection.Dispose Method (Boolean)

The Dispose method calls Close, and removes the OleDbConnection from the connection pool.

For detailed information see the Remarks section on the reference link to know about the case of releasing both managed and unmanaged resources.

like image 76
Niranjan Singh Avatar answered Oct 11 '22 16:10

Niranjan Singh