Delphi 2010 Web service help

Delphi 2010

I am trying to creat a DB connection to a MS SQL Server 2005 DB via a web service.

I have one call

function ConnectToDB(DBAlias: String): Boolean;stdcall;


I keep getting a "Inavalid argument: VPUCDS_VPN_SE01" error


What have i done wrong in adding the function parameter "DBAlias: String" to the routine?


When I had the following code in my webservice it worked fine

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;

Now that I have added the capability to pass the Alias in the call:

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


 i get the error

"Inavalid argument: VPUCDS_VPN_SE01"

see both the web service server and web service client code here:

http://www.shaneholmes.net/tmp/demo.zip


Thanks

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

systanCommented:
If is not a dll, Try to remove < stdcall; >   In stdcall, the parameters are removed by the called function.
if it is a dll,  Try to change to < export; stdcall;  >
0
DelphiRulezAuthor Commented:
its a webservice....CGI...and i believe its required
0
ebob42Commented:
Where did you place the .ini files? Are you sure the web service can find them? Make sure they are in the working directory, which may be different than the virtual directory where the CGI executable is deployed...

(and stdcall is required for SOAP methods, so leave that inside)
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

DelphiRulezAuthor Commented:
The ini files are in the folder with the executable and the DLL files.

Again, everything works great when the call is

function TTest.ConnectToDB: Boolean;stdcall;


but when i have

function ConnectToDB(DBAlias: String): Boolean;stdcall;


it fails
0
ebob42Commented:
So

 Conn.ConnectionName:= DBAlias;

fails, but

 Conn.ConnectionName:= 'VPUCDS_VPN_SE01';

works just fine ???



Change the function ConnectToDB(DBAlias: String): String; to return the string instead of a Boolean.

Set

  Result := DBAlias

and in the client check what the string is that's returned.


Double-check to see that you are calling the right web service - the one you've deployed. And that the .ini files are in that place as well.
0
systanCommented:
function ConnectToDB( Const DBAlias: String ): Boolean;stdcall;
0
ebob42Commented:
Systan: that's already the definition of the import routine:


  ITest = interface(IInvokable)
  ['{26F3F2AB-E760-9AA7-5A90-364B402E45E9}']
    function  ConnectToDB(const DBAlias: string): Boolean; stdcall;
  end;

Open in new window

0
DelphiRulezAuthor Commented:
So, instead of a webservice, here is a test executable i placed in the same folder with ini files and dll files and it worked just fine

unit UntMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SQLExpr, StdCtrls, DBXMsSQL, MidasLib;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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;

end.



I will try you suggestions bob

0
systanCommented:
//ADD const before declaring a string variable of your function parameter
function ConnectToDB( Const DBAlias: String ): Boolean;stdcall;

>Systan: that's already the definition of the import routine:
Yes, it is, but to remain it constant as it was
0
DelphiRulezAuthor Commented:
code from test application (WORKS!) Aopplication executable running in my web service folder just for testing purposes

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;





code from the actual Web service test(DOES NOT WORK!)

Notice i am not even passing the parameter (DBAlias)...instead, i hard code it



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;

0
DelphiRulezAuthor Commented:
so, im getting ""Inavalid argument: VPUCDS_VPN_SE01"  and i not even passing a Alias,
0
systanCommented:
Have you tried removing the stdcall ?

Stdcall is recommended, but its not required always.
0
DelphiRulezAuthor Commented:
yes, i tried
0
systanCommented:
Ok, Thanks, Listening only...
0
ebob42Commented:
So basically, you cannot connect as a Web Service,, even if the alias is hardcoded.

So the problem is not passing the Alias, the problem is assigning the Alias to the ConnectionName.

Most likely, the web service executable (CGI) is unable to find or read the .ini files. The working directory of the CGI executables could be different.

Check your IIS settings, and verify what the working directory of your virtual directory is (see the application  settings).
0
systanCommented:
Talking..
Ok check your TSQLConnection object properties, maybe VPUCDS_VPN_SE01 location is NOT pointed for web or in different location,  thats why its only working on standalone application
0
ebob42Commented:
One more check: if you use MS SQL, then often the default internet user cannot access the database using OSAuthentication. Make sure OSAuthentication is off.
0
DelphiRulezAuthor Commented:
checking that stuff now
0
DelphiRulezAuthor Commented:
ok, for authentication, i have:

Anonymous : Enabled
Basic : Disabled
Windows: Disabled


Under basic Settings for Virtual Directory,  I have

C:\inetpub\wwwroot\shanedev\

which is the folder i have the DLLs and INi Files in and where the test app worked fine, but the web service one did not
0
DelphiRulezAuthor Commented:
How do I tell TSqlConnection where the ini files are?
0
ebob42Commented:
The location of the .ini files is not the problem if the hardcoded alias also doesn't work... I have the feeling you are not allowed to connect to the database...
0
DelphiRulezAuthor Commented:
but i can with a non web service exe from that same path
0
ebob42Commented:
Yes, but a non-web service runs "as you" (a user, logged on into windows), and not as "default internet user" (which is the user that your CGI executable executes as), who has very little permissions on your machine and usually cannot connect to SQL Server databases for example.
0
DelphiRulezAuthor Commented:
sorry, i don't understand. Can you tell me how to change the permissions on IIS7?   I litterally have no experience with IIS7. I configured it using your e-book and marco cantus's info. Again, I can make a Web service run, I have created many demos (non database ones)....so I guess what i need is permissions to the DB from the web services folder (wwwroot\shanedev\) ??????

Im totally lost and very frustrated, Ive spent way too many hours i trying to do something that in the beginning i thought would be simple.
0
ebob42Commented:
Which version of SQL Server do you have? SQL Server 2005 Express?

You can add the application to an application pool, and set the identity for that pool.

I'm beginning to think this is more a deployment issue than a Delphi issue. I wish I could get my hands on your IIS7 machine to try to configure the app, but it's also too late now here (I'm going to bed, and next week need to visit some clients on site, so probably won't be online until later next week, sorry)...
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
DelphiRulezAuthor Commented:
Im using SQL Server 2005 on a MS Server 2008 machine

I have access via a VPN, since its my company's machine located in Seattle. Im in NY

Thanks for your help anyways

shane
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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.