How to properly close ADO connection to mdb file so ldb files goes away?

I have an app that uses ADO to connect to a Jet Engine .mdb file.   The user can open a form named frmBkUp, from the menu on the main form ,that has a button on it that when clicked runs the code listed below.  If the user clicks on the button once you see the message pop up saying "found ldb".  If they click on it again I get an access violation error.  

What I am trying to do is learn how to close all connections to the mdb file so the ldb file will go away.  My goal is to close all connections then copy the .mdb file to a location that the user selects, as a way for the user to backup their data.  I am closing all of the datasets in this code but I am not sure if that is neccessary.  Does anyone have any suggestions on how to accomplish this?

Thanks,
TD

{code}
procedure TfrmBkUp.Button1Click(Sender: TObject);
var
  ldbPath : string;
  searchResult : TSearchRec;
begin
  // Retrieve path to mdb lock file
  ldbPath := ExtractFilePath(Application.ExeName);

  // Try to find directories above the current directory
  SetCurrentDir(ldbPath);
  // Give exclusive connection to mdb file
  if datamodule1.ADOConnection1.Connected = True then
    begin
      DataModule1.ADOTable_tblProjects.Close;
      DataModule1.ADOTable_tblComments.Close;
      DataModule1.ADOTable_tblStates.Close;
      DataModule1.ADOTable_tblOSPManagers.Close;
      DataModule1.ADOTable_tblPManagers.Close;
      DataModule1.ADOTable_tblPercent.Close;
      DataModule1.ADOTable_tblEngineeringProvider.Close;
      DataModule1.ADOTable_tblConstructionProvider.Close;
      DataModule1.RvDataSet_Projects.DataSet.Active := False;
      DataModule1.RvDataSet_Projects.DataSet.Close;
      DataModule1.RvDataSet_Comments.DataSet.Active := False;
      DataModule1.RvDataSet_Comments.DataSet.Close;
      Datamodule1.ADOConnection1.Close;
      Datamodule1.ADOConnection1.Free;
      end;

  if FindFirst('*.ldb', faAnyFile, searchResult) <> 0 then
    begin
      showmessage('found ldb');
    end
  else
      showmessage('no ldb found');
end;
{code}
0
Thomas
2/8/2013 9:20:36 PM
embarcadero.delphi.ado 597 articles. 1 followers. Follow

5 Replies
1066 Views

Similar Articles

[PageSpeed] 45

Anyone ?
0
Thomas
2/9/2013 4:53:27 AM
On 2/8/13 11:53 PM, Thomas Lee wrote:
> Anyone ?
>

I use DAO instead of ADO, but I just close the database itself, make the 
copy, and then re-open it, along with all the associated tables.
0
Mike
2/9/2013 12:14:05 PM
> If they click on it again I get an access violation error.  

Er, right, because you've freed ADOConnection1 the first time around. I'd remove the Free call myself.

> What I am trying to do is learn how to close all connections to the mdb file
> so the ldb file will go away.  My goal is to close all connections then copy
> the .mdb file to a location that the user selects, as a way for the user to
> backup their data.

Having the LDB around doesn't prevent you from taking a copy of the MDB.
0
Chris
2/9/2013 4:23:57 PM
Hi Thomas,

You don't need to close the database to copy it.

I have a function that checks if I want to copy the database to a test
filename on startup that runs while a up to 25 people are using the
database. I programmatically copy the mdb file to a new filename. In
your case you may want to have 2 levels (grandfather / father / son)

Something like this:
   DeleteFile(PChar(Backup2Filename));
   CopyFile(PChar(Backup1Filename),PChar(Backup2Filename),False);
   DeleteFile(PChar(Backup1Filename));
   CopyFile(PChar(LivedataFilename),PChar(Backup1Filename),False);

Regards

Smurf
0
Ian
2/11/2013 12:05:50 PM
Thanks everyone !
TD

> {quote:title=Chris Rolliston wrote:}{quote}
> > If they click on it again I get an access violation error.  
> 
> Er, right, because you've freed ADOConnection1 the first time around. I'd remove the Free call myself.
> 
> > What I am trying to do is learn how to close all connections to the mdb file
> > so the ldb file will go away.  My goal is to close all connections then copy
> > the .mdb file to a location that the user selects, as a way for the user to
> > backup their data.
> 
> Having the LDB around doesn't prevent you from taking a copy of the MDB.
0
Thomas
2/12/2013 3:25:08 PM
Reply:

Similar Artilces:

ADO Connection from udl file
I would like to use file to connect MySQL database server. Can you advise or give me one example what the file looks like? Your help and information is great appreciated, Inung > {quote:title=Inung Huang wrote:}{quote} > I would like to use file to connect MySQL database server. > Can you advise or give me one example what the file looks like? > > Your help and information is great appreciated, > > > Inung Here is an example of a UDL file (C:\test.udl): [oledb] ; Everything after this line is an OLE DB initstring Provider=MSDASQL.1;Persist Sec...

using file.move
hey guys,i'm using file.move quite a bit in this project because it's an image gallery and i want users to be able to delete their files. however instead of actually deleting them, i'm using file.move to put them in a locked directory, just incase some sort of authority came asking about a file that someone tried to delete awhile ago. anyway i'm getting errors when trying SOMETIMES, because of your standard windows 'file is in use' error when trying to delete or move something.File.Move("C:\\files\\" + ((Label)gvr.FindControl("Label3")).Text, "...

Excel + ADO.NET + Closing Files?
Hello everybody, I am attempting to manipulate excel workbooks using ADO, and this has been working perfectly for some time on my development machine.I have started to run into problems with what appears to be the file handlers not being closed correctly (cant access file after completion etc). What is the best way of pinpointing this?At the end of any code path which has the file open for writing using ADO i close the file handler as such: objConn.Execute(strSQL)objConn.close()objConn = Nothing Is there any way (other than this code not being reached) that could result in the file bein...

to file:// or not to file://
(Firefox 1.5.0.6) I'm having trouble with HTML Anchors (links) using the file: protocol. The URL I'm trying to get at looks something like this file://///Host.Domain/Share/Dir1/Dir2/File.Ext If I click on the link, /nothing/ happens but, if I "Copy Link Location" and paste exactly the same thing into the "address bar" in FireFox, FireFox is perfectly happy to show me the file. Why the difference? Am I tripping over some security restriction here? Any suggestions? TIA, Phill W. Phill W. wrote: > (Firefox 1.5.0.6) > I'm ...

Inserting/Updating to ADO (.MDB file)
--=_D983EBAC.C2A3FD7A Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Could someone potentiall help me.. I'm getting a message saying that = this operation is not supported. It appears to be on the ->AddNew(); = method. How can I insert and update data in Access databases in my = question. What syntax can be used? I've already got reading solved. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D $rs->AddNew(); $rs->Fie...

Open and close the connections on the code behind file or class file is fast
Hi Friends, Method1: I am opening, performing some task and closing the connections from the sql server, no of time based on requirements on the code behind file.  Method2: Also I have gone through this post http://forums.asp.net/t/1193643.aspx and it is mentioned that fast and better performance we should open and close the connection on the class file. Please let me know for the fast execution of the .net application which method should I chose 1 or 2   Thanks, Farooq  Mark as answer if this post helpfull to you.Don't be afraid to be wrong; otherwise you...

File open/lock Monitor on one file closes when user accesses this file
Hello, we are running a DBase 4.1.1 MS-DOS application at Netware OES 6.5 SP4 (Novell Small Business Suite Server). Sometimes we are experiencing a slow down of the application when the server CPU ha about 5% and the disks are also not running heavy. There is nothing to find in the network too. What we found today is, that when a user accesses ex. file.dbf and we open the "File open/lock activity" Monitor on this file, the monitor closes immediately. We can shortly see the users session (nolock) before it closes. Are there any hints we can follow to find the backgrou...

Connection fails to load from app.config file using ADO.Entities in DAL
I have Data Access Layer setup where Entities are retrieved from a DB, everything is fine in design view... When I compile the project and deploy it, I get an error that says:The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.  So clearly somehow the app.config info is absent from the DLL. How can I resolve it. I don't want to put the Connection String in web.config because UI should now know anything about the Connection.Please let me know, thanks.  btw, nowhere even on the web I ca...

Convert Delphi 5 ADO App to Delphi 2007 ADO.NET
I have an appliction tha that is writen in Delphi 5 with ADOConnetion, ADOTable, and ADOQuery components. I need to upgrade to Delphi 2007 and use ADO.NET. I have the program building in with Delphi 2007. Is there anything I need to do to convert the ADO to ADO.NET? > I need to upgrade to Delphi 2007 and use ADO.NET. Why ? -- With best regards, Dmitry Arefiev AnyDAC (www.anydac.com) - Oracle, MS SQL Server, IBM DB2, MySQL, Firebird, Interbase, PostgreSQL, Sybase ASA, SQLite, MS Access, DBX, ODBC, InMem - universal high-speed native data access engine Reasons for ...

there are source files but no project file or solution file
I am working on a project, which only provides some .vb, .aspx, and other files. But there is no solution file or project file. How can I instal them in the development environment under .net visual studio 2005?   Thanks   David 1. Open Web Site from VS.NET 2005 to open this folder; 2. File -> Save All after you open the folder. VS.NET will pop up a window to let you save the project. Usually, after you save it, a .sln file will be saved to folder \Visual Studio 2005\Projects\YOURFOLDERNAME\ i f you don't change the folder for saving. Hope it helps."Objec...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

What's the difference between having an mdb file in a folder in solution explorer in VS and having the mdb file in SQL server?
 Hi,  I have always had my mdb file in sql server and been able to use it just fine without having it in a datafolder in vs. But, a lot of the times when I downloaded a sample for instance, the sample comes with the mdb file in the datafolder. What's the difference between having an mdb file in a folder in solution explorer in VS and having the mdb file in SQL server? And can it work if it's in VS and not in SQL server? Cheers, E Hi, there isnt much of a difference except that the data file is attached to SQL server at runtime where the other scenario already h...

Opening file...replace text...close file
HI, I'm new to this list. I would like to know how I can open an existing file on the server (windows). Search for some text and once found replace it with something else and then save/close the file. Thanks --------------------------------------------------- Colonel Nathan R. Jessop Commanding Officer Marine Ground Forces Guatanamo Bay, Cuba --------------------------------------------------- FlashGuy wrote: >HI, > >I'm new to this list. I would like to know how I can open an existing file on the server (windows). Search for some text and ...

how to convert Access MDB file into an ASCII file ?
Hi, I have opensuse 11 installed. I would like to know if from this OS, there's a way to export a Table from Microsoft Access MDB file, into CSV or ASCII text format? But I need it to run from the shell, because I would like to put this command into a script to run automatically. For example, something like this: mdbtools <filename.mdb> <table name> <output_filename.txt> -- newbie09 ------------------------------------------------------------------------ Trouble with access is that it uses microsoft's own formatting and not that many a...

Web resources about - How to properly close ADO connection to mdb file so ldb files goes away? - embarcadero.delphi.ado

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video - iMediaConnection.com
High-quality data, if not used properly, can still lead marketers to make bad decisions. Consider these common ways that numbers are used to ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

CareerSonar Turns Facebook Friends Into Job Connections
Looking for a job ? Among your Facebook friends lies the potential for employment. CareerSonar , a new service, brings together a person’s connections ...

Complex Regional Pain Syndrome: CPRS researchers study auditory connection
For 16 years Kerry Whyman ``secretly&quot; thought she had bone cancer and was dying secretly because she'd stopped telling doctors how much ...

Fictional Lawyers Use Their Family Connections Too
This film character had a family connection to his lawyer.

This Is How Facebook Is Working to Improve Experience On Slower Connections
... the globe, that’s not their situation . In recent years, Facebook has paid close attention to its user experience on 2G and other slow connections. ...

Addappt now lets you block contacts and connections
... gives you even more control than before. New features Block a current contact from connecting if they use Addappt down the road Block a connection ...

Facebook becomes more adept at dealing with crappy connections
... to get a decent phone signal to allow you to post a photo of your meal. Joking aside, in countries where people are struggling with 2G connections ...

Internet connections at UK universities have been knocked out by a 'persistent' cyber attack
... internet following a targeted cyber attack on a nationwide education network. The University of Manchester said on Tuesday its internet connection ...

Resources last updated: 12/12/2015 2:29:50 PM