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
DelphiRulezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

developmentguruPresidentCommented:
 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?
0
DelphiRulezAuthor Commented:
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
0
DelphiRulezAuthor Commented:
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.
0
developmentguruPresidentCommented:
You did not run my test for me.  Try doing the web service database connection with a different name.  My first attempt would be to ditch the underscores.  If the name is what it is complaining about, try to make a name that it has no conflict with.  I understand that you can get it to work from the same directory as an EXE, but that does NOT mean it should work in the same directory as a web service.  Something is stopping it and this is a simple test you can run to see if it give you any clues as to what is wrong.  Please give it a try (experimenting with different names - in the web service project) and let me know how it goes.

I would also still try to figure out what line in the ConnectToDB the error happens on.  Let me know.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.