Solved

2 Applications accessing the same database

Posted on 1997-05-21
13
158 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
code issue 8 128
Delphi Firemonkey Need Sample for Online Shopping Example. 2 139
Correct Component for Shopping Cart. 2 105
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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