Jump to content

ServerModule or MainModule?


Guest Efthymios Kalyviotis
 Share

Recommended Posts

Guest Efthymios Kalyviotis

Hello,

I have some small questions which I need your experience.

 

1) As far as I know (correct me if I am wrong), the server module is loaded only once (at the start of application). Also, the MainModule is loaded for every session that is being created by a browser.

 

When I want to create a TADOConnection for connection to an SQL Server, in which of the two modules is better to put the component?

If I put it in ServerModule, if the connection gets droped (for any reason), all my sessions will lose the connection to the DB. Right????

If I put it in MainModule, then a lot of connections will open simultanouesly and probably I will need SQL Server with a lot of licenses. :(

 

What do you sugest?

 

2) For services, a ServiceModule is also created. Should it be better to put my TADOConnection & TADODataSet's in it (or should I keep them inside the ServerModule)?

 

Thank you very much.

 

Efthymios Kalyviotis.

Link to comment
Share on other sites

You are exactly right and it is definitely an issue.

 

The safest and easiest option is to use MainModule. If you use ServerModule, losing connection to the database will probably be the least of your issues. Each of the MainModules run in separate threads. You will need to make sure that all data manipulation that you do in ServerModule is thread safe so each session is isolated from each other. With databases this can be a nightmare to handle.

 

The correct way to do it is probably some kind of middle way between these options. For example you could have the ServerModule create a pool of datamodules that each MainModule can borrow in turn. If you run out of data modules in the pool your client session will have to either wait a bit for a data module to become available or the operation has to fail in some predictable manner. Try to make data access operations proceed as swiftly as possible so there is least chance that a client will have to wait.

Link to comment
Share on other sites

Guest Efthymios Kalyviotis

But, If I have only the TADOConnection to the Server module and I put all the TADODatasets (+ datasources) to my MainModule (and ofcourse they refer to my Server module connection) isn't this going to solve the data manipulation problem? Aren't my sessions going to be isolated from each other?

Also, what about losing connections? Will the Datasets from MainModule that find disconnected ADOConnection enable the connection automatically when you do Active:= True?

 

Finally, have you found any issue by adding the TADOConnection on the Server Module when using the service uniGUI type?

I constantly have that message:

 

Service failed on start: CoInitialize has not been called.

 

And the CoInitialize wherever I put it doesn't do anything. Also the same happens even when ServerModule.AutoCoInitialize:= True.

 

UniGUI version: 0.87.0 build 901

 

Thank you!

Link to comment
Share on other sites

But, If I have only the TADOConnection to the Server module and I put all the TADODatasets (+ datasources) to my MainModule (and ofcourse they refer to my Server module connection) isn't this going to solve the data manipulation problem? Aren't my sessions going to be isolated from each other?

This is dangerous in my opinion unless you know for sure that TADOConnection is thread safe. Two queries could potentially interfere with each others data while they are being executed unless the TADOConnection takes special care to protect from this scenario. If you implement some kind of locking mechanism to ensure that only one thread can use TADOConnection at the time, then it would be safe. But then different sessions may have to wait for their turn to use the database.

 

All considerations that you would have when using a database from a multithreaded delphi application (using TThread typically) also applies to uniGUI applications.

 

Montri's suggestion of keeping all DB access out of process for instance using Datasnap is very good and definitely worth consideration.

 

Also, what about losing connections? Will the Datasets from MainModule that find disconnected ADOConnection enable the connection automatically when you do Active:= True?

Yes, but again it may not be safe to use TADOConnection in a multithreaded environment.

 

Finally, have you found any issue by adding the TADOConnection on the Server Module when using the service uniGUI type?

I constantly have that message:

 

Service failed on start: CoInitialize has not been called.

 

And the CoInitialize wherever I put it doesn't do anything. Also the same happens even when ServerModule.AutoCoInitialize:= True.

 

UniGUI version: 0.87.0 build 901

 

Thank you!

I don't have a solution to this.

Link to comment
Share on other sites

  • Administrators

Well, ServerModule is not the right place to put your Database connection components. A single database connection can not be shared in a multi-threaded environment. So you must put your AdoConnection on MainModule.In future we may develop built-in pooling mechanisms for uniGUI which will enable application to share Modules among sessions. You can also use a middle-tier which handle such tasks for you such as Data Abstract.

 

For your licensing considerations I don't think SQL server is licensed per TCP connection. Actually their licensing scheme is a myth for me. That said, the server itself doesn't impose any restriction on number of connections. It is only limited by system resources.

Link to comment
Share on other sites

  • Administrators

Finally, have you found any issue by adding the TADOConnection on the Server Module when using the service uniGUI type?

I constantly have that message:

 

Service failed on start: CoInitialize has not been called.

 

And the CoInitialize wherever I put it doesn't do anything. Also the same happens even when ServerModule.AutoCoInitialize:= True.

 

UniGUI version: 0.87.0 build 901

 

Thank you!

 

ServerModule will not perform proper COM initializations required for ADOConnection. MainModule is the right place for this.

Link to comment
Share on other sites

ServerModule will not perform proper COM initializations required for ADOConnection. MainModule is the right place for this.

 

I have a question about this. I put two Connections: 1 in ServerModule for Timer's Task for general purpose, and 1 in MainModule that is for accesing data from Applications. I got not errors when I open Connection in ServerModule, and I got not errors in timer's tasks. The question is: Is this wrong or it must be keeped as is now????

Link to comment
Share on other sites

  • Administrators

I have a question about this. I put two Connections: 1 in ServerModule for Timer's Task for general purpose, and 1 in MainModule that is for accesing data from Applications. I got not errors when I open Connection in ServerModule, and I got not errors in timer's tasks. The question is: Is this wrong or it must be keeped as is now????

 

What sort of Timer is this?

Link to comment
Share on other sites

Guest Efthymios Kalyviotis

OK. You have both convinced me. I will move my TADOConnection from the ServiceModule that already is inside the MainModule. I have found a lot of articles about ADO that say that it is a COM-based technology and uses apartment-threaded objects (each thread its own connection).

:angry:

 

I really appreciate for your help. :)

 

PS.

SQL Server Express doesn't have any limit on TCP connections and doesn't check them. MS on the other hand says that no more than 5 connections at the same time are permited to the server (more than 5 will continue to work but is illegal and will actually need to buy at least the standard edition with more licenses).

Link to comment
Share on other sites

You can also use a middle-tier which handle such tasks for you such as Data Abstract.

 

also kbmMW is an option. I have got good results until now with the combo Unigui/kbmMW. Used it mainly because of the RecNo-problem with DBIsam, but the potential of separating the db-layer from the Unigui logic is much higher. Working with some "services" in a kbmMW-server for db access (and other maybe error prone tasks, like printing) I expect the level of uptime of the core Unigui application to raise.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...