How release the active connection to an Access database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:arial,sans-serif; font-size:10px <span>Hi, <br/>
<br/>
<span>Im working in a Visual C++ (Visual Studio 2008) project where I need access to an Access database (by an OleDbConnection), perform certain operations on database and finally (after closing the connection to the database), package database in a
.zip file <span>with other files.<br/>
<br/>
<span>The problem is, after I connect to the Access database, perform some operations on it and close the connection, it still gets as "caught" and I cant access to it!
<span style="font-family:arial,sans-serif; font-size:10px <span style="font-family:arial,sans-serif; font-size:10px Even closing the connection, if I try to access to the database (even if I do outside of my application, through windows explorer) or I
try to reopen the connection to the database, the .mdb file gets caught and I cant open it because the database still is in use.<br/>
<br/>
<strong style="font-family:arial,sans-serif; font-size:10px How can I release, completly close and finalize the connection to a database? <span style="font-family:arial,sans-serif; font-size:10px How I can force the closure of
the connection to the database? How can I free the use of my .mdb file? <br/>
<br/>
<span style="font-family:arial,sans-serif; font-size:10px I have read many solutions or proposals as:
<span style="font-family:arial,sans-serif; font-size:10px <span> http://msdn.microsoft.com/en-us/library/ms810829.aspx http://msdn.microsoft.com/en-us/library/ms810829.aspx
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.releaseobjectpool(v=VS.80).aspx http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.releaseobjectpool(v=VS.80).aspx
...b<span style="font-family:arial,sans-serif ut still I didnt solve my problem. :o(
<span style="font-family:arial,sans-serif; font-size:10px <span> <br/>
<span>My code is:<br/>
<br/>
private: System:: Data:: OleDb:: OleDbConnection ^ DbConnectionDestino;<br/>
<br/>
Initialization of the connection: passing the path of the database you want to connect and the connection mode (in my case Share Exclusive mode, so only I can access to the database while connection is open):<br/>
private: bool IniConnectionDB (String ^ pathDB, String ^ connectionMode)<br/>
{<br/>
<span style="white-space:pre String^
<span style="font-family:arial,sans-serif; font-size:10px StrAccessConnDestino<span style="font-family:arial,sans-serif; font-size:10px = "Provider = Microsoft.Jet.OLEDB.4.0; OLE
DB Services =- 4; Data Source =" + pathBD + "Mode =" + connectionMode; <br/>
<span style="white-space:pre this-> DbConnectionDestino = gcnew System:: Data:: OleDb:: OleDbConnection (strAccessConnDestino);<br/>
<br/>
<span style="white-space:pre try<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre this-> DbConnectionDestino-> Open () / / opens the connection<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre catch (OleDbException ^ ExOLEDB)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre MessageBox:: Show (ExOLEDB-> Message, "Error creating connection to the target database:" + pathBD,
<span style="white-space:pre MessageBoxButtons:: OK, MessageBoxIcon:: Error);<br/>
<span style="white-space:pre return false;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre return true;<br/>
}<br/>
<br/>
<span style="font-family:arial,sans-serif; font-size:10px And function to close the connection:<span style="font-family:arial,sans-serif; font-size:10px <br/>
private: System:: Void CerrarConexionBDDestino ()<br/>
{<br/>
<span style="white-space:pre this-> DbConnectionDestino-> Close ();<br/>
<span style="white-space:pre this-> DbConnectionDestino-> ReleaseObjectPool ();

<span style="font-family:arial,sans-serif; font-size:10px }
<span style="font-family:arial,sans-serif; font-size:10px <span><br/>

<span style="font-family:arial,sans-serif; font-size:10px Any solution?

<span style="font-family:arial,sans-serif; font-size:10px Thanks & regard,<span><br/>

<span style="font-family:arial,sans-serif; font-size:10px Aitor

View the full article
 

Similar threads

D
Replies
0
Views
101
Donald Uko
D
T
Replies
0
Views
120
The real Slartibartfast
T
P
Replies
0
Views
190
prasad127
P
A
Replies
0
Views
161
ANIL AYDINALP
A
Back
Top