Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IB server is taking too many resources!

Status
Not open for further replies.

cyberant

Programmer
Sep 21, 2003
44
ZA
Hey Everyone

I've created a program that rebuilds a corrupt database. The program works perfectly but when the rebuild has completed, I press alt-ctrl-del, and find that IBServer is utilising over 100MB of resources, this causes the system to be very sluggish. If I disable the server in control panel and then restart it, my problem is solved, but I'd like the process to be more automatic. Is it possible to restart the IBserver programatically in Delphi. Any suggestions would be helpful!

Thanks!
 
Not sure if this is the correct approach to solving problem (maybe better to see why its consuming so much resources in the first place) but here is some code to start the Interbase Service programitically :


* S t a r t S e r v e r ( )
*
****************************************************************
* Author: The Client Server Factory Inc.
* Date: March 1, 1999
*
* Input:
*
* Return:
*
* Description:
*
*****************************************************************
* Revisions:
*
*****************************************************************}
Function StartServer(): boolean;
Var
lRegistry: TRegistry;
lStartUpInfo: STARTUPINFO;
lSecurityAttr: SECURITY_ATTRIBUTES;
lProcessInfo: PROCESS_INFORMATION;
lEXEName: String;
lArray: Array[0..255] Of char;
Begin
result := False;
lRegistry := TRegistry.Create;
Try
Screen.Cursor := crHourglass;
lRegistry.RootKey := HKEY_LOCAL_MACHINE;
If Not lRegistry.OpenKey('Software\Borland\InterBase\CurrentVersion',
False) Then
ShowMessage('InterBase server is not installed on your system.')
Else
lEXEName := Format('%s%s -a', [lRegistry.ReadString('RootDirectory'),
'bin\ibserver.exe']);
ZeroMemory(@lStartUpInfo, SizeOf(lStartUpInfo));
lStartUpInfo.cb := SizeOf(lStartUpInfo);
lSecurityAttr.nLength := SizeOf(lSecurityAttr);
lSecurityAttr.lpSecurityDescriptor := Nil;
lSecurityAttr.bInheritHandle := True;
If CreateProcess(Nil, StrPCopy(lArray, lEXEName), @lSecurityAttr, Nil,
False, 0, Nil,
Nil, lStartUpInfo, lProcessInfo) <> Null Then
result := True
Else
ShowMessage('The server could not be started.')
Finally
lRegistry.Free;
Screen.Cursor := crDefault;
End;
End;

And just 2 other code snippets that may be useful :

* StopService ( )
*
****************************************************************
* Author: Unknown
* Date: Sept 2003
*
* Input:
*
* Return: true/False (success)
*
* Description: Stops a service on Windows XP/NT/2000
*
*****************************************************************}

function ServiceStop(aMachine,aServiceName : string ) : boolean;
// aMachine is UNC path or local machine if left empty
var
h_manager,h_svc : SC_Handle;
svc_status : TServiceStatus;
dwCheckPoint : DWord;
begin
h_manager:=OpenSCManager(PChar(aMachine),nil,
SC_MANAGER_CONNECT);
if h_manager > 0 then
begin
h_svc := OpenService(h_manager,PChar(aServiceName),
SERVICE_STOP or SERVICE_QUERY_STATUS);

if h_svc > 0 then
begin
if(ControlService(h_svc,SERVICE_CONTROL_STOP,
svc_status))then
begin
if(QueryServiceStatus(h_svc,svc_status))then
begin
while(SERVICE_STOPPED <> svc_status.dwCurrentState)do
begin
dwCheckPoint := svc_status.dwCheckPoint;
Sleep(svc_status.dwWaitHint);

if(not QueryServiceStatus(h_svc,svc_status))then
begin
// couldn't check status
break;
end;

if(svc_status.dwCheckPoint < dwCheckPoint)then
break;

end;
end;
end;
CloseServiceHandle(h_svc);
end;
CloseServiceHandle(h_manager);
end;

Result := SERVICE_STOPPED = svc_status.dwCurrentState;
end;

Check if service is already running :

Function IsIBRunning(): boolean;
Begin
If GetWindow(GetDesktopWindow, GW_HWNDNEXT) = FindWindow('IB_Server',
'InterBase Server') Then
result := False
Else
result := True;
End;

As you may guess, this represents code I have found on this issue and is from various sources. You will need to change as you feel necessary.

Hope this helps..

Opp.



 
Thanks a million!! I'll give it a try. Even if it doesn't prove useful now, I'm sure it'll come in handy in the future!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top