Delphi 2010 ve Delpi XE2 aynı pc üzerinde kullanımı!
Destek talebi(Lütfen oy verelim!)
Sitemiz üye alımına kapatılmıştır!
! CODEBANK 2012 !
İNDİRMEK&DETAYLI BİLGİ ALMAK İÇİN BURAYI TIKLAYINIZ.
0 Üye ve 1 Ziyaretçi konuyu incelemekte.
procedure TForm1.Button3Click(Sender: TObject);begin WinExec('C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqlmangr.exe', SW_SHOW or SW_MINIMIZE or SW_SHOWMINIMIZED);end;
procedure TForm1.FormCreate(Sender: TObject);var sqlServerName:TStrings; i:Integer;begin sqlServerName:=TStringList.Create; GetSQLServerList(sqlServerName); for i := 0 to sqlServerName.Count-1 do ComboBox1.Items.Add(sqlServerName.Strings[i]); sqlServerName.Free; str_exe:=ExtractFilePath(Forms.Application.ExeName); ComboBox1.ItemIndex:=0;end;
private { Private declarations } public { Public declarations } str_exe:string; end;var Form1: TForm1; IsExists:Boolean = False;const MSSQL_98StartCommand = 'scm -action 1 -pwd "%s"'; MSSQL_NTStartCommand = 'net start mssqlserver'; MSSQL_98StopCommand = 'scm -action 6'; MSSQL_NTStopCommand = 'net stop mssqlserver';implementationuses SQLServerLists;{$R *.dfm}
function IsNT:Boolean;begin Result:=(Win32MajorVersion >= 4) and (Win32Platform = VER_PLATFORM_WIN32_NT);end;function IsExistsMSSQL:Boolean;const MSSQLSERVER = 'SOFTWARE\Microsoft\MSSQLServer';var Reg:TRegistry;begin Result:=IsExists; if Result then Exit; if not IsNT then Reg:=TRegistry.Create else Reg:=TRegistry.Create(KEY_READ); with Reg do try Reg.RootKey := HKEY_LOCAL_MACHINE; Result := KeyExists(MSSQLSERVER); IsExists := Result; finally Free; end;end;
//sql server başlatfunction StartMSSQL(Pass:string):Boolean;var S: string;begin Screen.Cursor:=crHourGlass; try if not IsNT then S:=Format(MSSQL_98StartCommand, [Pass]) else S:=MSSQL_NTStartCommand; try WinExec(PChar(S), SW_HIDE); Result:=True; except Result:=False; end; finally Screen.Cursor:=crDefault; end;end;
//sql server durdurfunction StopMSSQL:Boolean;begin Screen.Cursor:=crHourGlass; try try if not IsNT then WinExec(MSSQL_98StopCommand, SW_HIDE) else WinExec(MSSQL_NTStopCommand, SW_HIDE); Result:=True; except Result:=False; end; finally Screen.Cursor:=crDefault; end;end;
//sql server durumufunction GetSqlServerStatus(lpszComputerName: LPCTSTR): Integer;var ssStatus: SERVICE_STATUS; dwOldCheckPoint: DWORD; dwStartTickCount: DWORD; dwWaitTime: DWORD; dwStatus: DWORD; lpszServiceName: LPCTSTR; schSCManager: SC_HANDLE; schService: SC_HANDLE;begin if (lpszComputerName <> nil) and ((StrComp(lpszComputerName, '127.0.0.1') = 0) or (StrComp(lpszComputerName, '.') = 0)) then lpszComputerName := nil; lpszServiceName := 'MSSQLServer'; schSCManager := OpenSCManager( lpszComputerName, //Computer name nil, // ServicesActive database SC_MANAGER_ALL_ACCESS); // full access rights if schSCManager = 0 then GetSqlServerStatus := -1; //Machine not exists schService := OpenService( schSCManager, // SCM database lpszServiceName, // service name SERVICE_ALL_ACCESS); if schService = 0 then begin CloseServiceHandle(schService); GetSqlServerStatus := -2; //SqlServer Service not Exists end; if not QueryServiceStatus( schService, // handle to service ssStatus) then begin // address of status information structure CloseServiceHandle(schService); GetSqlServerStatus := -3; //MyErrorExit('QueryServiceStatus'); end; Result := ssStatus.dwCurrentState;end;function SqlServerStatus(MachineName:string):string;var SrvStatus:integer; str:string;begin SrvStatus:=GetSqlServerStatus(pChar(MachineName)); case SrvStatus of 1:str:='Stopped '; 2:str:='Starting '; 3:str:='Stopping '; 4:str:='Running '; 5:str:='Restarting after being paused '; 6:str:='Pausing '; 7:str:='Paused '; end; Result := str;end;
procedure TForm1.SpeedButton1Click(Sender: TObject);begin if StartMSSQL('.') then begin sleep(3000); StatusBar1.Panels[0].Text:=SQLServerStatus(ComboBox1.Text)+'-'+'\\'+ComboBox1.Text+'-'+'MSSQLServer'; Image1.Picture.LoadFromFile(str_exe+'runningserver.bmp'); SpeedButton1.Enabled:=false; SpeedButton2.Enabled:=true; end else begin end;end;
procedure TForm1.SpeedButton2Click(Sender: TObject);begin if Forms.Application.MessageBox(Pchar('\\'+ComboBox1.Text+ ' üzerinde MSSQLSERVER servisini DURDURMAK istiyor musunuz?'),'SQL Server Service Manager',MB_YESNO+MB_ICONINFORMATION)=ID_YES then begin StopMSSQL; sleep(3000); StatusBar1.Panels[0].Text:=SQLServerStatus(ComboBox1.Text)+'-'+'\\'+ComboBox1.Text+'-'+'MSSQLServer'; Image1.Picture.LoadFromFile(str_exe+'stopserver.bmp'); SpeedButton1.Enabled:=true; SpeedButton2.Enabled:=true; end;end;