Login failed in Service Application

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
John Hay
Posts: 2
Joined: Wed 30 Aug 2006 16:40

Login failed in Service Application

Post by John Hay » Wed 30 Aug 2006 16:51

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

John Hay
Posts: 2
Joined: Wed 30 Aug 2006 16:40

Post by John Hay » Wed 30 Aug 2006 16:52

Sorry about the formatting

I have tried loginprompt as false and true

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Thu 31 Aug 2006 08:16

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

RandySill
Posts: 14
Joined: Sat 21 Oct 2006 11:42

Post by RandySill » Sat 21 Oct 2006 11:50

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

Post Reply