Delphi 2010 DataSnap with multiple server modules

Hi,

We're going to upgrade the multi-tier project from Delphi 2007 to 2010 using
DataSnap. That is, we will convert the Remote Data modules to DataSnap
server modules. Previously (in D2007) we shared one ADO connection between
the remote data modules, I've managed to share the ADO connection between
the DataSnap server modules. It (APP Server) "seems" work fine, however,
some colleague mentioned that ADO is not thread safe. If that's the case, is
there any easy way to verify the issue?

BTW, to keep the minimal changes to the existing remote data modules, we
have to use ADO connection for now. In this case, what're the best practices
for using ADO connection? Is that enough to use its own ADO connection in
each server module if couldn't use the shared one. Also, at the end the new
App Server will be run as a Service application. Is there any different?

Thanks.

Michael
0
Michael
8/13/2010 12:31:41 AM
embarcadero.delphi.multi-tier 396 articles. 0 followers. Follow

6 Replies
1649 Views

Similar Articles

[PageSpeed] 53

Hi Michael,

> We're going to upgrade the multi-tier project from Delphi 2007 to 2010 using
> DataSnap. That is, we will convert the Remote Data modules to DataSnap
> server modules. Previously (in D2007) we shared one ADO connection between
> the remote data modules, I've managed to share the ADO connection between
> the DataSnap server modules. It (APP Server) "seems" work fine, however,

You could have one "main" Server Methods object (derived from data 
module) that autocreates the other "child" data modules for you for the 
particular request, placing the TADOConnection on top of the main server 
methods object. If you use a LifeTime of Session, that would give you a 
unique TADOConnection for each session (alternatives for LifeTime are 
Invocation, which gives you a unique TADOCOnnection for each request, or 
Server, which will give you one instance for all requests - which is not 
safe indeed).

> some colleague mentioned that ADO is not thread safe. If that's the case, is
> there any easy way to verify the issue?

ADO not thread safe? In what sense? Sure, if you have the LifeTime set 
to Server, then you get one TADOConnection for all incoming connections, 
which is not thread safe, but a LifeTime of Session or Invocation will 
give each thread (session or request) its own TADOConnection, which is 
then thread safe.

Please ask "some colleague" to clarify what he/she meant by the comment.

> BTW, to keep the minimal changes to the existing remote data modules, we
> have to use ADO connection for now. 

Why? What prevents you from using SQLConnections (for example) on the 
data modules?

> Michael

Groetjes,
           Bob Swart

-- 
Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi
Chairman Delphi Development Network (DDN) powered by SDN - www.sdn.nl
Embarcadero Technology Partner - Delphi & RAD Studio Reseller BeNeLux
http://twitter.com/eBob42 LinkedIn: http://nl.linkedin.com/in/drbob42
Delphi Win32 & .NET books on Lulu.com: http://stores.lulu.com/drbob42
Personal courseware + e-mail support http://www.ebob42.com/courseware
Blog: http://www.drbob42.com/blog - RSS: http://eBob42.com/weblog.xml
0
Bob
8/14/2010 9:20:36 AM
Hi Bob,

> You could have one "main" Server Methods object (derived from data 
> module) that autocreates the other "child" data modules for you for the 
> particular request, placing the TADOConnection on top of the main server 
> methods object. If you use a LifeTime of Session, that would give you a 
> unique TADOConnection for each session (alternatives for LifeTime are 
> Invocation, which gives you a unique TADOCOnnection for each request, or 
> Server, which will give you one instance for all requests - which is not 
> safe indeed).
> 

I'm facing a similar issue, having converted an older app server that uses COM 
and has many child TRemoteDataModules.  

I have a TSQLConnection in my "main" Server Methods 
object, and I do in fact get a unique TSQLConnection for each session.  Each 
session may or may not be connected to the same SQL Server database.
LifeCycle=Session.

How do I pass the unique TSQLConnection from the Server Methods object
to each of the session's "child" data modules?

I am not sure how to do the "autocreate" bit.

Thanks in advance for the clarification.

Regards,
Jim Elden
0
Jim
8/25/2010 2:51:41 PM
Solved.

instantiate TSQLConnection in Server Methods unit e.g. "ServerMethodsUnit1.pas".
Add var to hold the instance of TSQLConnection in the Server Methods unit after class declaration.

var
  SQLConn: TSQLConnection;

In DSServerModuleCreate,

  SQLConn := SQLConnection1;

add ServerMethodsUnit1 to uses of the interface of the "child" remote data modules.

In child data module's OnCreate, set all datasets' SQLConnection property to SQLConn declared in ServerMethodsUnit1.




-- 
Jim
0
Jim
8/25/2010 5:53:36 PM
> {quote:title=Jim Elden wrote:}{quote}
> Solved.
> 
> instantiate TSQLConnection in Server Methods unit e.g. "ServerMethodsUnit1.pas".
> Add var to hold the instance of TSQLConnection in the Server Methods unit after class declaration.
> 
> var
>   SQLConn: TSQLConnection;
> 
> In DSServerModuleCreate,
> 
>   SQLConn := SQLConnection1;
> 
> add ServerMethodsUnit1 to uses of the interface of the "child" remote data modules.
> 
> In child data module's OnCreate, set all datasets' SQLConnection property to SQLConn declared in ServerMethodsUnit1.
> 
> 
> 
> 
> -- 
> Jim

Probably SQLConn as threadvar instead of var is safer, or not?
0
Hanno
8/25/2010 9:29:40 PM
> You could have one "main" Server Methods object (derived from data 
> module) that autocreates the other "child" data modules for you for the 
> particular request, placing the TADOConnection on top of the main server 
> methods object. If you use a LifeTime of Session, that would give you a 
> unique TADOConnection for each session (alternatives for LifeTime are 
> Invocation, which gives you a unique TADOCOnnection for each request, or 
> Server, which will give you one instance for all requests - which is not 
> safe indeed).

Thanks, Bob.

There are my understandings of "autocreates the other "child" data modules":

Create the child data modules objects in main data module, and pass adoconnection on main to the children; and introduce new functions to return the child data modules objects;

Could you please clarify whether my understanding is what you meant? Also by doing this, can we still invoke the application server methods in the child data module?

BTW, given that child data modules being created in main data module, do I still need to expose the classes of child data modules by hooking up the TDSServerClass components? Or only one TDSServerClass component for the main data module?

> > BTW, to keep the minimal changes to the existing remote data modules, we
> > have to use ADO connection for now. 
> 
> Why? What prevents you from using SQLConnections (for example) on the 
> data modules?
> 

We have lots of ADODataSet components on the main/child data modules, we're not going to convert them to SQLDataSet until we find an easy way;

And we've done some experiment as below. That is, use the same ADOConnection, which is on ServerContainer unit, for both Main and Child data modules; In this case, it'll only have one database connection (checked by stored proc sp_who2) no matter how many clients are running. According to some articles, it should be one database connection per session (between client and app server). 

There are our concerns.

1. Is that thread safe?
2. If there are hundreds of clients at the same time, will it be the bottleneck with only one connection?

procedure TDSServerModule2.DSServer1Connect(
  DSConnectEventObject: TDSConnectEventObject);
begin
  CoInitializeEx(nil,COINIT_APARTMENTTHREADED);
end;

procedure TDSServerModule2.DSServer1Disconnect(
  DSConnectEventObject: TDSConnectEventObject);
begin
  CoUninitialize;
end;

procedure TDSServerModule2.SetADOConnection(const DSSrvModule: TDSServerModule);
var
  i: integer;
begin
  // set up database connection
  with DSSrvModule do
  begin
    for i := 0 to ComponentCount - 1 do
      if ((Components[i] is TADODataset) or (Components[i] is TADOStoredProc) or
         (Components[i] is TADOQuery)) and (Components[i].Tag = 0) then
        TADODataset(Components[i]).Connection := acServer
      else
        if (Components[i] is TADOCommand) and (Components[i].Tag = 0) then
          TADOCommand(Components[i]).Connection := acServer;
  end;
end;

procedure TDSServerModule2.CreateDSInstance(
  const PersistentClass: TPersistentClass;
  DSCreateInstanceEventObject: TDSCreateInstanceEventObject);
var
  SrvModule:  TDSServerModule;
  DSClass:    TPersistentClass;
begin
  DSClass := PersistentClass;

  if DSClass <> nil then
  begin
    if not DSClass.InheritsFrom(TProviderDataModule) then
      exit;

    SrvModule := TDSServerModuleClass(DSClass).Create(nil);
    SetADOConnection(SrvModule);
    DSCreateInstanceEventObject.ServerClassInstance := SrvModule;
  end;
end;

procedure TDSServerModule2.MainServerClassCreateInstance(
  DSCreateInstanceEventObject: TDSCreateInstanceEventObject);
begin
  CreateDSInstance(TMainRDM, DSCreateInstanceEventObject);
end;

procedure TDSServerModule2.ChildServerClassCreateInstance(
  DSCreateInstanceEventObject: TDSCreateInstanceEventObject);
begin
  CreateDSInstance(TChildRDM, DSCreateInstanceEventObject);
end;

Thanks in advance.
0
Michael
9/8/2010 7:11:55 AM
We've implemented a pool (list) of ADO connections creating them on DSServer connect event, releasing them on DSServer disconnect event and assigning them on DSServerModule createinstance event. Something like this: http://rjwerning.blogspot.com/2010/11/delphi-2010-sharing-database-connection.html
0
Irina
12/22/2010 10:21:20 PM
Reply:

Similar Artilces:

from delphi 6 to delphi 2010
Hi. It is possible, with component RX, dxforumlibrary, InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. Thank by comments. excequiel arostica wrote: >Hi. > It is possible, with component RX, dxforumlibrary, >InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. > >Thank by comments. Rx is dead and sources are taken over by jcl/jvcl. I dont know about the rest of the components and i have no experiences with bde over the last 9 years. excequiel arostica wrote: > Hi. > It is possible, with component RX, dxforumlibrary,...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

Price of upgrade from Delphi 2010 Professional to Delphi 2010 Enterprise?
It's weird, but I could not find the answer on so simple question not in Embarcadero Shop, neither by the forum search. For example, the shop info about Enterprise upgrade says: The Upgrade product is available to registered owners of 2006-2009 versions, blah-blah... So, if I'm Delphi 2010 Professional user, I even not eligible for upgrade? I have to buy a new version of Enterprise??? But if I'm Delphi 2006 Professional user, I can upgrade. Please clarify this nonsense for me. Exact question is in the subject. Thanks! Hi Dmitri, > It's weird, but I could not...

Iphone monotouch client <-> Delphi 2010 datasnap server
So, Monotouch has been released and it is now simpler to get into making iphone apps (and soon also android apps). But what is the easiest way to tie an monotouch developed iphone client to a delphi 2010 datasnap server? Any ideas? Rant: "Monotouch" should have been a delphi tool. Then it would have flown of the shelves! But noooo. Not even in the next version is such fat clients and native compiled enviroments catered for. Instead there are talks about linux, mac os, etc. *sigh* Rants are not productive and kill one's desire to be helpful. Fortunately, I decided to...

ANN: DataSnap-like Client-Server JSON RESTful Services in Delphi 7-2010 [Edit]
How to implement a very useful service... say... adding two numbers? In our framework, you code Server-Side: {code} function TSQLRestServerTest.Sum(aRecord: TSQLRecord; aParameters: PUTF8Char; const aSentData: RawUTF8; var aResp, aHead: RawUTF8): Integer; var a,b: Extended; begin if not UrlDecodeNeedParameters(aParameters,'A,B') then begin result := 404; // invalid Request exit; end; while aParameters<>nil do begin UrlDecodeExtended(aParameters,'A=',a); UrlDecodeExtended(aParameters,'B=',b,@aParameters); end; aRes...

Delphi 2010 professional to Delphi XE3
Hello, Sorry for this is not right place to ask this question: I have Delphi 2010 professional version, I like to upgrade to Delphi XE3 Am eligible to upgrade or no not? I like answer from Delphi sales team. I couldn’t find email to ask them. Thanks Mike Thomas <> wrote in news:506459@forums.embarcadero.com: > Hello, > > Sorry for this is not right place to ask this question: > I have Delphi 2010 professional version, I like to upgrade to Delphi > XE3 Am eligible to upgrade or no not? I like answer from Delphi > sales team. I couldn’t find emai...

Migrate from Delphi 2007 to Delphi 2010
Hi All, Thanks in advance for your help. Below is my query, Currently I am using Delphi 2007 and i want to migrate to Delphi 2010. 1. What all things i need to take care while doing this? 2. What all third party components will get impacted? 3. Any known issues in Delphi 2010 which might impact the cause? 4. Any changes in database operation required as i am using Oracle? Hope I have post this query under correct category. If not sorry for the trouble and could you please suggest me the correct category for this? Looking forward for your response. Have a great day. Th...

Migrating From Delphi 7 to Delphi 2010
We did not know which forum was the best for this question. We have been wanting to migrate from Delphi 7 to a later version for years but it appears to be a daunting task. We first looked at D2006 and that was a radical new world. We bought D2010 a couple of years ago and not done much with it because there are so many parts to our applications. We have done a few new applications in D2010 and they seem to work okay. D2010 has not been impressive, perhaps because of the strangeness compared to D7. Is is possible for us to do a phased sort of migration where we do a form at a time? ...

delphi 2006 code in delphi 2010
hello, is there any option to make delphi 2006 code work in delphi 2010? something like in java IDEs where you can define the code level you like to use? the problem is, that i made a project with 2006 and sent it to my customer. they got 2010 and it compiles fine, but it just doesn't work. it deals with en-/decryption of text, we assumed, that it has something to do with ansi vs. unicode strings... but we cant find the exact position where the error occurs. i am a bit dissapointed, because everywhere i read that the new IDE will always be downwards compatible and so on.. but in ...

Delphi 2010 w Delphi 2007
I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). Can I install D2010 on this machine without it affecting D2007? Will D2010 affect D2007 in any way? Thanks, Randall Carpenter > {quote:title=Randall Carpenter wrote:}{quote} > I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). > Can I install D2010 on this machine without it affecting D2007? Will D2010 > affect D2007 in any way? Won't hurt a thing. I have D7, RAD Studio 2007, RAD Studio 2009, and RAD Studio 2010 all on my desktop system and they coexist fine. Jus...

Free RAD Studio 2010 and Delphi Prism 2011 with purchase of Delphi 2010
Hi All, For those of you who complain that Delphi (and RAD Studio) is too expensive... for a few short weeks there are two overlapping special offers from Embarcadero that you can use to move up to RAD Studio 2010 including the latest Delphi Prism 2011 for the price of a single Delphi 2010 (New User or Upgrade)... The first "RAD Studio PROMO" offer is still valid until June 28th: when you order Delphi 2010, you get RAD Studio 2010 delivered instead (including Delphi 2010, C++Builder 2010 and Delphi Prism 2010). As of May 26th, the "Delphi Prism 2011" of...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

Can Delphi 2010 DataSnap work with DataSnap CGI application?
Hi, I managed to create an DataSnap ISAPI DLL works with IIS and it works well. I may now use TDSProviderConnection with TSQLConnection (using DataSnap as driver) in client side to consume the ISAPI services. This time, I try create a CGI Datasnap server application.to replace the ISAPI DLL. I managed to create the CGI datasnap server. However, my client doesn't able to consume the services. It either hang forever, or prompt "HTTP/1/1 500 session expired". Does anyone have ideas what's going on? Or the Delphi 2010 datasnap doesn't works with CGI? -- Best...

Delphi 7 to Delphi 2010
We have decided to move up some applications running under Delphi 7 to Delphi 2010. However, I was surprise to see that simply recompiling the application causes the application to be much slower than version 7. We have a lot of string transformation routines, some mathematical transformations, etc. When I mean slower, I mean up to two times slower than with Delphi 7, so it not a minor difference. (The EXE is also a lot bigger but I don't worry too much about that). Is there something I can do to obtain the same kind of speed I had in Delphi 7 but with Delphi 2010? ...

Web resources about - Delphi 2010 DataSnap with multiple server modules - embarcadero.delphi.multi-tier

Companies Directory - Job Fusion
D1 Locker D2L D4D Technologies DAA Deutsche Auftragsagentur Dabble Dabble DB Dabee Dabizmo DabKick Dabo Health Dacentec Dachis Group ...

Embarcadero Webinars
Advanced software tools for application developers and database professionals. Cross-platform solutions for database design, development and ...

David I - Head is in the cloud, feet planted firmly in the ground
... I’s (David Intersimone) Embarcadero blog about programming, languages, databases, history, and more. , and filed under Cloud Computing , DataSnap ...

RAD Studio 2015 Roadmap
Rad Studio, Delphi, C++Builder, and Appmethod 2015 Technology Roadmap from JT at EmbarcaderoTechnologies

FireMonkey Q&A
Questions and answers from a FireMonkey webinar

Contact Us - Ginktage
Home Privacy Policy Contact Us Home .NET Events Microsoft Office SQL Server Tools Gadgets Technology Tips&Tricks Contact Us Ginktage Learn , ...

News Briefs: December 15, 2008 - SD Times: Software Development News
AccuSoft creates an SDK for Web imaging software, while Artisan releases a free version of Artisan Studio. Also, Bredex, Embarcadero, Ilog and ...

Craig Stuntz’s Weblog : Site Map
Craig Stuntz’s Weblog F# • Compilers • Programming Languages • Functional Programming • Web Skip to content Home About Site Map Site Map Share ...

iBeacon Hack Makes It More Efficient To Wait Tables
Here at the 2014 TechCrunch Disrupt SF hackathon two-man hack team, Ray Ho and Mark Watson, showed off a simple but promising concept that combines ...

Te Waka o Delphi · Poll Archives
Keeping Delphi afloat in Aotearoa

Resources last updated: 11/22/2015 5:36:28 PM