Solved

Advice on applying TDatabase at application.

Posted on 2004-09-08
5
164 Views
Last Modified: 2010-04-05
Currently, I am developing an application.  This exe application will be used by several users at different PC, but connecting to a database sit on a server.

I always face error prompting "lock conflict".  Is it caused by the way I code the program ?  This is some of the examples I code in my program :-

First of all I have a data module where a TDatabase component is placed.

Then

    dm.db.StartTransaction;
    try
    ................
       dm.db.Commit;
   except
       dm.db.rollback;
       raise;
   end;

I have all my various forms pointing to this data module ( named "dm" ) 's database ( named "db" ).  I suppose this might cause deadlock ??

Please advise on how I should construct such kind of application in the aspect of database, especially when saving data.
0
Comment
Question by:ivylnm
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12004595
Several Q's:

Which Delphi version?
You're using the BDE, right? Is it set up correctly to use a lock file on a fileshare in your network?
Which database type? (SQL Server, Oracle, Paradox)

If you're using the BDE, the BDE must create a file to keep track of locks in the database. If every user has his own application with BDE, then they must be set up to use a lock file on a shared folder. This is done by using the NetFileDir property of the database SESSION object. Best thing to do is adding a TSession to your datamodule, give it a name, set it up to point to a network folder and make sure your database and tables are looking at this session...

And perhaps upgrade to ADO with either SQL Server, Oracle or MS Access. Then these problems are less likely to happen.
0
 

Author Comment

by:ivylnm
ID: 12012423
I am using Delphi 7 developing application and connecting to Interbase database, using TDatabase, TQuery components.

0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12014616
Well, since you're using the BDE, you need to set up a shared folder for the lock file. Doesn't matter if you're using Paradox, DBase, Oracle or Interbase. If you share a database connection through the BDE to a database, you need to share the lock file amongst ALL users or else the BDE gets conflicts. (Because the BDE on System A is saying that record X is unlocked while the BDE on system B has this record locked...)
With Interbase, you might want to change to the Interbase database components instead. They're more native.

In the past, I've solved these kinds of problems by creating a multi-tier solution. That way, you only have one system that needs to keep track of all the locks and database transactions. It does require a lot of additional code and a dedicated system as middle-tier system. The advantage however is that none of the clients would need to install the InterBase client software, though...
0
 

Author Comment

by:ivylnm
ID: 12023164
So do you mean that using Interbase components would be much more suitable in this kind of application ?

Can you show me details of the second paragraph of your comment ? I don't quite understand.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 125 total points
ID: 12026086
The InterBase components communicate directly with InterBase itself, not through the BDE or whatever else. Thus you have a bit of a performance gain.

About multi-tier applications, there are many alternatives for this but it means you have to create two applications. It is very useful for medium to large companies where many users must share the same database. You will have an X amount of client PCs and one PC that is set up as middle-tier. (MT) Then another PC that is used as database server, although middle-tier and database server could be the same system, if you want to conserve resources.

For the MT you create an application that will arrange the communication between the clients and the database (server). The communication from the MT to the database is simple throught the BDE, though the InterBase components or perhaps even through ADO. The communication with the clients can be either through simple TCP/IP, DCOM or COM+ or by SOAP/Webservices. It just depends on what you favour as a solution. If you prefer TCP/IP then the MT is just an executable that you start once, which then waits for communications from the client(s). With DCOM or COM+ you just develop COM objects which get activated by the system. The client just activates these COM components remotely, the component then starts processing. SOAP/Webservices is a bit comparable to COM+ but the difference is that it's more XML-based and often combined with a webserver. Basically, a SOAP server is just a special kind of ISAPI DLL that's used by IIS to provide webpages to clients. (In these cases, not real webpages but XML files.)

But Multi-tier technologies are a bit hard to learn if you're completely inexperiences with it. It easily takes about 3 to 6 months before you finally get a good understanding of the technology. Not because it's complex but because it is a very large topic. And you probably end up learning a lot of stuff about COM and ActiveX.

My personal preference is COM+, btw. Delphi 7 doesn't support SOAP as well as I've hoped. (Delphi has some compatibility problems since they didn't exactly follow the SOAP specifications.) To send data from server to clients I used ADO for the recordsets but that's because it's the easiest technique if you're using SQL Server. With InterBase you would use Midas/ClientDataset or perhaps you convert the recordsets to XML data and send the XML to the client.

The advantage for the clients is that they don't require any database logic. So no InterBase clients on their systems that need to be configured. All the client applications need to know is the server with the Middle-tier software. The middle-tier then provides them the information in whatever format they prefer. Basically, all the client would need is a single executable. Your application.

The big advantage is that technically, only one system is talking to the database thus that single system can keep track of all the locks. The disadvantage is that it takes a lot of study, a lot of experimenting and a new way to develop software. Basically, you're dividing the system into multiple logical blocks. The clients who just display the data, the middle-tier that does most of the processing of the data and the database server that just stores everything. Complex, but powerful. (Besides, if you ever need to use a different database, all you have to change is the middle-tier. None of the users would see any difference.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

21 Experts available now in Live!

Get 1:1 Help Now