// Code by Edward Guo function QryService (pService: PChar; var dwState: DWORD; pSvcType: PDWORD): Integer; var hSvcMgr, hService: SC_HANDLE; rStatus: TServiceStatus; begin Assert (pService<>nil); if pService[0]=#0 then begin Result := EC_SERVICE_GETNAME; Exit; end; hSvcMgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); if hSvcMgr=0 then begin Result := EC_SERVICE_MANAGER; Exit; end; hService := OpenService(hSvcMgr,pService,SERVICE_QUERY_STATUS); if hService=0 then begin CloseServiceHandle(hSvcMgr); Result := EC_SERVICE_OPEN; Exit; end; if QueryServiceStatus(hService,rStatus) then begin Result := EC_NO_ERROR; dwState := rStatus.dwCurrentState; if pSvcType<>nil then pSvcType^ := rStatus.dwServiceType; end else Result := EC_SERVICE_QUERY; CloseServiceHandle(hService); CloseServiceHandle(hSvcMgr); end;检查dwState返回值。pService是服务的“服务名称”,自己去查。
ADOConnection1.Connected:=true;
ShowMessage('连接成功');
except
ShowMessage('连接失败');
end;//不过,这种方法不能排除其它原因。
在dos下输入
C:\>sqlplus username/password@serviceName
不过我想会有高手来答的!
// Code by Edward Guo
function QryService (pService: PChar; var dwState: DWORD; pSvcType: PDWORD): Integer;
var
hSvcMgr, hService: SC_HANDLE;
rStatus: TServiceStatus;
begin
Assert (pService<>nil); if pService[0]=#0 then
begin
Result := EC_SERVICE_GETNAME;
Exit;
end;
hSvcMgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if hSvcMgr=0 then
begin
Result := EC_SERVICE_MANAGER;
Exit;
end;
hService := OpenService(hSvcMgr,pService,SERVICE_QUERY_STATUS);
if hService=0 then
begin
CloseServiceHandle(hSvcMgr);
Result := EC_SERVICE_OPEN;
Exit;
end; if QueryServiceStatus(hService,rStatus) then
begin
Result := EC_NO_ERROR;
dwState := rStatus.dwCurrentState;
if pSvcType<>nil then pSvcType^ := rStatus.dwServiceType;
end else
Result := EC_SERVICE_QUERY; CloseServiceHandle(hService);
CloseServiceHandle(hSvcMgr);
end;检查dwState返回值。pService是服务的“服务名称”,自己去查。