Solved

2 Applications accessing the same database

Posted on 1997-05-21
13
149 Views
Last Modified: 2010-04-04
I am trying to post information from two different applications to the
same database.  One application reads information from an HTML page and
posts the information to the database.  The other application accesses the
same databases (with Tsessions and Tdatabases pointing to the same
locations) over a LAN.  However, when the following scenario occurs:

1. the LAN application is active
2. information is posted through the web-based form
3. a new record is added through the LAN based form

the web-based information never gets posted to the database.  (There is an
autoincrement field in the main table as well).

Any information anyone can provide on how to fix this problem shall be
greatly appreciated.

0
Comment
Question by:boriso
  • 7
  • 3
  • 3
13 Comments
 
LVL 1

Expert Comment

by:jackb022197
ID: 1336509
>the web-based information never gets posted to the database.
Try debugging the web-app and see if you get an exception when posting the data to the table
>(There is an autoincrement field in the main table as well).
After posting you have a blank record with only the auto-inc field filled??

0
 

Author Comment

by:boriso
ID: 1336510
The web-app works fine on its own.
After posting from the web-app, all fields are correctly entered, the problem only occurs when the LAN application is open and 1)the web-based application posts a record and 2)the LAN application posts a record.  In common terms, the records from the web app seem to be put on queue when the LAN based application is open.  If the LAN based program is closed, and there are any records from the two applications with the same number in the autoincrement field, those records on queue from the web-app appear to just get "thrown out."
0
 
LVL 1

Expert Comment

by:jackb022197
ID: 1336511
Do you have the CachedUpdates property of your table set to True for your apps?? Set this to False and see if that helps...
 
0
 

Author Comment

by:boriso
ID: 1336512
Cached updates is already set to false for both apps
0
 
LVL 1

Expert Comment

by:jackb022197
ID: 1336513
Try this and see if you still lose posts:

procedure TForm1.Table1AfterPost(DataSet: TDataSet);
begin
  DBiSaveChanges(Table1.Handle)
end;

For this to work you should add dbiProcs to your uses clause.


0
 

Author Comment

by:boriso
ID: 1336514
That did not work either.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:buemoh
ID: 1336515
I had this problem too, but I'm using a small information file, which tells both application if it is possible to add a new record or not.

That means:

Build a indication file, which can be accessed from both application via locking algorithm.

each application has to write down in this indication file what she is doing (reading/writing)

If one application wants to add, delete, change a database entry, proof if there's the othere application reading/writing and if not, lock the indication file and do database access.

This is the way I've done, because this is secure and works fine. (I've 150 Web-clienst ofer the network and three database-application-clients)

Bye

Hartwig

-----------------------------------------------------------------------------------------------------
///\\\ Hartwig MOTAL ///\\\  e-mail: moh@bue.magwien.gv.at
 Weinberggasse 60/9/7, A-1190  Vienna/Austria/Europe

0
 

Author Comment

by:boriso
ID: 1336516
That would work fine, but I have the autoincrement field which cannot be edited.  Entries coming in via the web are returned a page indicating the autoincrement field since that field is utilized as the user's ID.  I need to be able to return the page ASAP when entries are made from the web.  Data entry is being made all day from the LAN application, so the above method would not work well.
0
 

Author Comment

by:boriso
ID: 1336517
That would work fine, but I have the autoincrement field which cannot be edited.  Entries coming in via the web are returned a page indicating the autoincrement field since that field is utilized as the user's ID.  I need to be able to return the page ASAP when entries are made from the web.  Data entry is being made all day from the LAN application, so the above method would not work well.
0
 
LVL 1

Expert Comment

by:buemoh
ID: 1336518
I'm not locking the database - only the indication file.

Therefore, I get always a right autoincremented value, which can be used as unique User-ID.

If you get some informations from the web which should be put in the database you don't have to write some value in the autoincremented field, because the BDE does this for you.
You can only read this autoincremented field value and use it.

You've only to be shure that not to applications wants to put a new entry in the database at the same time.

0
 

Author Comment

by:boriso
ID: 1336519
Adjusted points to 175
0
 

Author Comment

by:boriso
ID: 1336520
I am awarding buemoh an "A" for answering my question.
0
 
LVL 1

Accepted Solution

by:
buemoh earned 170 total points
ID: 1336521
Hallo boriso,

hope our discussion have helped you.

If not, I can try to define everything clearer and write some source.

-------- some part of our "private" e-mail discussion ------- BEGIN --

Dear Ed,

now, I'm trying to declare my method in detail:

1) the indication file holds an array for each assigned application and a summary field of attached applications.
That means:
  { each attached appliaction get's a new number }

type
  tIndicationRecord = record
    dwTotalAttachments   : dword;
      { total number of attached applications }
    tAttachedNumber      : array [1..1000] of DWORD;
      { each application get's her own identification number }
  end;


2) If an application needs database access, first it tries to LOCK the indication-file and increment the dwTotalAttachments and find out, which tAttachedNumber isn't zero and can be yours, which has to be hold in the application for identification and cleaning after detachment. If the indication-file is allready LOCKED, then the application has to try it for a defined time until it can LOCK the indication-file or terminat with an error, like: SORRY, TOO MANY CONNECTIONS OPEN. PLEASE TRY IT LATER.
Here some pseudo-code:

repat
  try
    lock indication-file
    do update of indication file
    read/write database
  except
    increment timeout
  end;
until (indication-file locked) or (timeout = 10000);


3) If LOCKING was successfull, the application can write/read from the database quickly and afterwards UNLOCK the indication-file.


In my case, I've a more detailed indication-file which gives some more special information, including the value of any autoincrement-field.

If you've problems, may be I'm able to write some code for you.

Now, explaning your questions about speed:

1) all LAN database applications are opened, but this applications have always to LOCK the indication-file as well as the web-applications first before they can access the database.

2) the web-applications are a little bit slower, then without of LOCKING the indication-file, but this are only milliseconds or seconds on a network with more then 20.000 machines over hole Vienna on different speed lines from glas to modem.

3) with extrafields in the indication-file you can speed up the web-applications, because implement a dwReading : dword; field and let each web-application, which only wants to read LOCK the indication-file, fill in this field and UNLOCK. Afterwards you can read, but the LAN-application can see with this field, that an update isn't possible yet.


The hole indication-file should be planed on what you need.

-------- some part of our "private" e-mail discussion ------- END ----

Bye

Hartwig

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now