You are not logged in.
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
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
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
Offline
thanks,ab,
it does work after using administrator user to run the service.
Offline