delphi web service with database access

soozh
soozh used Ask the Experts™
on
Hello,

I have built a web service using delphi rad 2010.  

I want to access an ms sql server database to update some tables with data.

I have placed the dbGO components (TConnection, TADODataset etc) on the TWebModule page but always get an access violation when i try to use them from my "implementation".

Should i be using an ordinary tdatamodule?  Or am i missing a call to coInitialize?  

Any tips or example code would be welcome!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
This former EE post seems to be about the same problem...
Delphi 2010 Web Service using DBExpress and MS SQL Server 2005 DB ?

Check, if it helps you...
soozhCEO

Author

Commented:
no that does not help... the quetion is not related to mine.. and the author does not really get an answer anyway....

My compents are visible and are on the TWebModule.  Should i be able to access them successfull?
Geert GOracle dba
Top Expert 2009

Commented:
have you actually instantiated your webmodule  ?

instantiating:
var WebModule: TWebModule;
begin
  WebModule := TWebModule.Create(nil);

Open in new window


if you don't do this manual
before using the WebModule ... check if it is nil or not

if Assigned(WebModule) then
begin
  // Do your stuff
end else
  Raise Exception.Create('Webmodule not initialised');
soozhCEO

Author

Commented:
yes the webmodule is instantiated... i can actually call some methods in it... but none of the visual dbgo compenents.

I all i need to know is if it is possible... if it is then i must look at my code...
Oracle dba
Top Expert 2009
Commented:
yes, it's possible

coInitialize will have to be called for webservices as all programming is running in a thread

you'll have to display some code to let people help you
soozhCEO

Author

Commented:
ok now i have made it work.  I added a Tdatamodule to my code.  And then in the method that was doing all the work i just created it:

    dmZooshMS := TdmZooshMS.Create(nil);
    try


    .... use it....

   finally
      dmZooshMS.Free ;
   end ;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial