Page 1 of 1

Login failed in Service Application

Posted: Wed 30 Aug 2006 16:51
by John Hay
I am having trouble with a Service application trying to login to a server
When I call DoConnect I get an errorcode 18452 and message

Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection.

The code which is causing the problem is as follows

procedure TMyThread.DoConnect(sender:tobject);
var
i:integer;
begin
i := CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
if i S_OK then
logerror('err - ' + IntToStr(i))
else
begin
try
try
logerror('try to connect');
logerror(msconnection1.ConnectString);
msconnection1.connect;
logerror('connected');
upload;
except
end;
finally
couninitialize;
end;
end;
end;

constructor TMyThread.create;

begin
inherited create(true);
msconnection1 := tmsconnection.Create(nil);
msconnection1.Authentication := auserver;
msconnection1.Server := 'JOHN-LAPTOP';
msconnection1.Database := 'Impact';
msconnection1.Username := 'sa';
msconnection1.Password := 'password';
msconnection1.LoginPrompt := true;
msquery1 := tmsquery.Create(nil);
msquery1.Connection := msconnection1;
end;

I know the parameters are all OK as if I drop a TMSConnection component on the service app and set its connetced property to true it connects.

The ConnectString logged is

Provider=SQLOLEDB.1;User ID=sa;Password=password;Data Source=JOHN-LAPTOP;Initial Catalog=Impact;Persist Security Info=True

which also works fine if I paste it into a TMSConnection on a form.

Any ideas what going on?

John

Posted: Wed 30 Aug 2006 16:52
by John Hay
Sorry about the formatting

I have tried loginprompt as false and true

Posted: Thu 31 Aug 2006 08:16
by Jackson
Unfortunately we couldn't reproduce the problem.
Please send us (sdac*crlab*com) a complete small test project to reproduce the problem; it is desirable to use Northwind or Master schema objects, otherwise include definition of your own database objects; don't use third party components

Also supply us following information
- Exact version of Delphi
- Exact version of SDAC. You can see it in About sheet of TMSConnection Editor
- Exact version of Microsoft SQL Server and OLE DB provider that you use. You can see it in Info sheet of TMSConnection Editor

Posted: Sat 21 Oct 2006 11:50
by RandySill
Is your Service application using Local System authority or using authentication of it's own? If writing a service that will connect to a database server on a remote computer, login authentication will be required (set in Control Panel, Services, Properties). If the service is running on the same machine as the database server, then Local System works fine.

Randy