Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Concurent insert into database

Posted on 2012-03-20
2
Medium Priority
?
344 Views
Last Modified: 2012-03-21
Hello experts!

My application reads data sent through the Internet.

I use IdTCPServer to read the data.

Sometimes it is lots of data and easy approach like:

onExecute:
 with DataModule2.ZQuery1 do
     begin
       Close;
       Params[0].AsInteger := 1;
       Params[1].AsDateTime := Today;
       Params[2].AsString := lineOfData;
       ExecSQL;
       ApplyUpdates;

     end;

works fine but is not stable, after some time it crashes.

What approach would be appropriate here?

Thank you

panJames
0
Comment
Question by:panJames
2 Comments
 
LVL 28

Accepted Solution

by:
Sinisa Vuk earned 2000 total points
ID: 37745952
Seem that you have few concurrent request for write to db with globally defined query.

you can two ways:
- create query component each time data comes or

- useing critical sections ... so define global variable like :

var
  LockDB: TRtlCriticalSection;

Open in new window


... on botton of unit before 'end.' add....

...
initialization
  InitializeCriticalSection(LockDB);

finalization
  DeleteCriticalSection(LockDB);

Open in new window


... and on Execute :

...
  EnterCriticalSection(LockDB);
  try
    with DataModule2.ZQuery1 do
     begin
       Close;
       Params[0].AsInteger := 1;
       Params[1].AsDateTime := Today;
       Params[2].AsString := lineOfData;
       ExecSQL;
     end;
  finally
    LeaveCriticalSection(LockDB);
  end;

...

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 37745956
the approach depends on a some considerations
> what type of database ? oracle, mssql, interbase ?

you are adding 1 line at a time or is this 1 line the whole text file ?
what is this lineofdata ?

for your delphi approach there are several considerations
are you catching all the errors ? and handling them appropriately ?
what do you do when the database is down ? eg for maintenance
what happens if you lose connection ?

for the database > is there space enough, are you archiving/deleting old data ?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question