i));
end;
result :=rtn;
except
on E :Exception do
begin
application.MessageBox(Pchar(‘取網絡中的SQLSERVER列表出錯了‘+E.message),‘系統提示‘,MB_OK+MB_ICONSTOP);
end;
end;
end;
//刪除資料庫
procedure dropDatabase(serverName,LoginName,LoginPassword,dataBaseName:String);
var
osqlServer:_SqlServer;
begin
try
osqlServer :=coSqlserver.Create;
osqlServer._AddRef;
osqlServer.Connect(serverName,LoginName,LoginPassword);
osqlServer.Databases.Remove(dataBaseName,‘owner‘);
oSqlServer.DisConnect;
osqlServer._Release;
oSqlServer :=nil;
except
on E:Exception do
begin
application.MessageBox(Pchar(‘刪除資料庫錯誤:‘+E.Message),‘系統提示‘,MB_OK+MB_ICONSTOP);
end;
end;
end;
//創建資料庫
procedure createDatabase(serverName,LoginName,LoginPassword,dataBaseName:String);
var
odataBase :_Database;
oDBFileData :_DBFile;
oLogFile :_LogFile;
osqlServer :_SqlServer;
begin
try
osqlServer :=cosqlServer.Create;
osqlServer._AddRef;
osqlServer.Connect(serverName,LoginName,LoginPassword);
odataBase :=coDataBase.Create;
odataBase._AddRef;
oDBFileData :=coDBFile.Create;
oDBFileData._AddRef;
oLogFile :=coLogFile.Create;
oLogFile._AddRef;
oDataBase.Name :=dataBaseName;
oDBFileData.Name :=dataBaseName;
oDBFileData.PhysicalName :=oSqlServer.Registry.SQLDataRoot +‘\data\‘+dataBaseName+‘.mdf‘;
oDBFileData.PrimaryFile :=true;
oDBFileData.Size :=2;
oDBFileData.FileGrowthType := SQLDMOGrowth_MB;
oDBFileData.FileGrowth := 1;
oDatabase.FileGroups.Item(‘PRIMARY‘).DBFiles.Add(oDBFileData);
oLogFile.Name :=dataBaseName+‘Log‘;
oLogFile.PhysicalName :=oSqlServer.Registry.SQLDataRoot +‘\data\‘+dataBaseName+‘.ldf‘;
oLogFile.Size :=2;
oDatabase.TransactionLog.LogFiles.Add(oLogFile);
oSqlServer.Databases.Add(oDatabase);
osqlServer.DisConnect;
oSqlServer._Release;
oSqlServer :=nil;
oDataBase._Release;
oDataBase :=nil;
oDBFileData._Release;
oDBFileData :=nil;
oLogFile._Release;
oLogFile :=nil;
except
on E:Exception do
begin
application.MessageBox(Pchar(‘創建資料庫錯誤:‘+E.Message),‘系統提示‘,MB_OK+MB_ICONSTOP);
end;
end;
end;
//停止SQLSERVER代理
procedure stopJobServer(serverName,LoginName,LoginPassword:String);
var
oSqlServer :_SqlServer;
oJobServer :JobServer;
begin
try
oSqlServer :=coSqlServer.Create;
oSqlServer._AddRef;
osqlServer.Connect(ServerName,LoginName,LoginPassword);
oJobServer :=osqlServer.JobServer;
if (oJobServer.Status=SQLDMOSvc_Running) then
begin
OjobServer.Stop;
end;
oSqlServer.DisConnect;
oSqlServer._Release;
oSqlServer :=nil;
except
on E :Exception do
begin
application.MessageBox(Pchar(E.Message+‘停止SQLSERVER代理錯誤!‘),‘系統提示‘,MB_OK+MB_ICONSTOP);
end;
end;
end;
//啟動SQLServer代理
procedure startJobserver(serverName,LoginName,LoginPassword:String);
var
oSqlServer :_SqlServer;
oJobServer :JobServer;
begin
try
oSqlServer :=coSqlServer.Create;
oSqlServer._AddRef;
osqlServer.Connect(ServerName,LoginName,LoginPassword);
oJobServer :=osqlServer.JobServer;
if (oJobServer.Status<>SQLDMOSvc_Starting) and (oJobServ