#1 2012-06-14 01:43:17

profh
Member
Registered: 2010-07-02
Posts: 161

TSQLDBStatement.Execute can not execute in the windows service

the following function can execute in a TForm ,but can not in a TService,why?

function execsql;
var
  OleDBConnectionProperties:TOleDBConnectionProperties;
  SQLDBConnection:TSQLDBConnection;
  Query: TSQLDBStatement;
begin
  result := false;

  OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
  OleDBConnectionProperties.ConnectionString := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource';
  SQLDBConnection := OleDBConnectionProperties.NewConnection;
  Query := SQLDBConnection.NewStatement;
  try
    Query.Execute('insert into mytable(ccode) values(12345)',false);
  except
    Query.Free;
    exit;
  end;

  Query.Free;
  result := true;

end;

Offline

#2 2012-06-14 06:21:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,656
Website

Re: TSQLDBStatement.Execute can not execute in the windows service

Do another OleDB provider (e.g. the Jet/MSAccess one) work in a service?

Online

#3 2012-06-14 11:00:06

profh
Member
Registered: 2010-07-02
Posts: 161

Re: TSQLDBStatement.Execute can not execute in the windows service

use the following connectionstring,it works in a service:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\aa.mdb;Persist Security Info=False

BTW,with "Provider=MSDASQL.1;Persist Security Info=False;Data Source=mysource" connectionstring,i used "mysql-connector-odbc-5.1.11-win32" to connect mysql...

Last edited by profh (2012-06-14 11:09:32)

Offline

#4 2012-06-14 12:09:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,656
Website

Re: TSQLDBStatement.Execute can not execute in the windows service

Therefore, the OleDB layer as implement by SynOleDB / SynDB works as expected.

So I guess the issue comes from the OleDB ODBC provider itself.
Or even the ODBC layer. Certainly some user rights issue, or the DB not published for all users of the computer.

When run from a Service, applications are launched with not your current user.
You may try to set the user running the server (in the properties), or tune ODBC to define the DB for all users, or at least the user assigned to the service.

I've never done that, so I do not know how to do it, but I guess this is the direction you'll have to go.
See http://social.msdn.microsoft.com/Forums … fa796cfec5

Online

#5 2012-06-15 09:12:56

profh
Member
Registered: 2010-07-02
Posts: 161

Re: TSQLDBStatement.Execute can not execute in the windows service

thanks,ab,

it does work after using administrator user to run the service.

Offline

Board footer

Powered by FluxBB