Link to home
Start Free TrialLog in
Avatar of DelphiRulez
DelphiRulez

asked on

Delphi 2010 Web Service using DBExpress and MS SQL Server 2005 DB ?


Delphi 2010, dbExpress, and MS SQL Server 2005 DB

Ok,

I am trying to make a connection to a MS SQL 2005 DB using Delphi 2010 & DBExpress.

If I create a standard delphi application executable and hard code my connection (IT WORKS!):

I can run this from my web server vitual directory C:\inetpub\wwwroot\shanedev\

here is the code (again, this is not a web service, just a standard delphi app)
procedure TForm1.Button1Click(Sender: TObject);
var
 Conn: TSQLConnection;
begin
 Conn:= TSQLConnection.Create(nil);
 Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
 Conn.LoadParamsOnConnect := True;
 Conn.LoginPrompt:=True;
 try
   Conn.Connected:= True;
   if Conn.Connected then
   ShowMessage('Connected!')
   else
   ShowMessage('NOT Connected!')
 finally
  Conn.Free;
 end;
end;

NOTE: All the ini files, and DLLs reside in the same folder as my executable

and yes, I have DBXMsSQL & MidasLib in the uses clause

again, it works if its not a web service!



However, if i then move the code over to a Web serices CGI module:

function TTest.ConnectToDB: Boolean;stdcall;
var
 Conn: TSQLConnection;
begin
 Conn:= TSQLConnection.Create(nil);
 Conn.ConnectionName:= 'VPUCDS_VPN_SE01';  
 Conn.LoadParamsOnConnect := True;
 Conn.LoginPrompt:=True;
 try
   Conn.Connected:= True;
   result:=  Conn.Connected;
 finally
  Conn.Free;
 end;
end;

It does NOT work! I get an error message "Inavalid argument: VPUCDS_VPN_SE01".


Why will it work from standard app executable and not web services CGI executable???????

Thanks

Shane
Avatar of developmentguru
developmentguru
Flag of United States of America image

 It may seem like an odd test, but have you tried changing the name of the connection?  That is what it is complaining about.  I would try several different things starting as simple as I could (Like "A").  See if you get any different reaction.  Experimentation like this has been able to show me, in the past, that the spot of code I am working on does not like (as an example) the underscore character.

  Why might it behave this way?  I would need to get into the source of the control.  It is possible that the control uses different APIs based on the type of application it is in.  The programmers at CodeGear / Embarcadero may have found a significant speed increase for database based web services by using this approach.

  I would also be interested in seeing which line the error happens on.  Does it happen when you assign the name?  Or, does it happen when you set connected to true?
Avatar of DelphiRulez
DelphiRulez

ASKER

again, that name works fine. It runs with a standard delphi app. It wont run as a webservice

it has to do with the configuration of the IIS7 somehow.

However, it is in relation to the MS SQL Server 2005 DB as well.

I can run non db test web services and they work fine

I just can't reach the database from my web working folder using a web service
I have also gave the following a try:

SERVER CODE:

function TTest.ConnectToDB: Boolean;stdcall;
var
 Conn: TSQLConnection;
 Ex: ConnectionException;
begin
 Conn:= TSQLConnection.Create(nil);
 Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
 Conn.LoadParamsOnConnect := True;
 Conn.LoginPrompt:=False;
 try
   Conn.Connected:= True;
   result:=  Conn.Connected;
   Conn.Free;
 except
 begin
  Ex:= ConnectionException.Create('Connection Failed!');
  raise Ex;
 end;
 end;
end;

CLIENT CODE:

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
  GetITest.ConnectToDB;
  except on E: ConnectionException do
   ShowMessage(E.ClassName + ': ' + E.Message + #10#13 +
               'FaultActor: ' + E.FaultActor + #10#13 +
               'FaultCode: ' + E.FaultCode + #10#13 +
               'FaultDetail: ' + E.FaultDetail + #10#13 +
               'FaultReason: ' + E.FaultReason + #10#13 +
               'FaultReasonLang: ' + E.FaultReasonLang + #10#13 +
               'FaultNode: ' + E.FaultNode +#10#13 +
               'FaultRole: ' + E.FaultRole);
  end;
end;
end.


I didn't learn anything from the response

see screenshot here: http://www.shaneholmes.net/tmp/screenshot.jpg

again, I can run a standard delphi app executable from the same folder (wwwroot) and conenct to the database, i just can't do it with a web service executable. However, I can create demo web services that work as long as they are not DB related.
ASKER CERTIFIED SOLUTION
Avatar of developmentguru
developmentguru
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial