Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the correct way to open and close a access database in Delphi?

Status
Not open for further replies.

Morne10

Programmer
Jun 15, 2010
2
GB
I am using TADOTable, TDataSetProvider and TDataSource for each table in my access database. The application need to typical work like word or excel, in that when you open the program you start with a clean file, and then you can save this file, or load a already saved one.

I am using the following code to load a database file, but clearly I am missing something:

If OpenDialogSite.Execute Then
Begin
Dir := ExtractFilePath( Application.ExeName );
ADOTablePanels.Close;
ADOTableSite.Close;
WorkingFileName := Dir + 'DBs\Site.mdb';
OpenFileName := OpenDialogSite.FileName;
CopyFile(PChar(OpenFileName),PChar(WorkingFileName),False);
ADOTablePanels.Open;
ADOTableSite.Open;
End;

With Site.mdb containing both Panels table and Site table.

When I try to change data in the tables afterward, I get the error “The microsoft jet database engine has stopped the process because you and another user are attemping to change the same data at the same time”. My application runs on a single PC, and is not a remote server type application. Which means only I am accessing the database. However somehome I must be accessing it twice?

Any suggestions welcome, as I have been stuck for quite a few days already.
 
Perhaps try adding a TADOConnection to your application and use that to connect to the database. Connect the TADOTables to your TADOConnection.
 
Hey I tried it, and it seems to work!!!!
I will keep on testing, but at first round it seems to completely resolve my issue.

Thanks for the recommendation!!!!!!

However what is the difference between using a TADOTable with a connection string, and using a TADOConnection with a connectionstring and this connected to the TADOTable?
 
When you associate the two TADOTables to the same TADOconnection they will share the connection - otherwise your two components will each make their own connection which may have led to your error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top