我試圖創建一個Windows應用程序,使用Transfer對象將數據庫從一臺服務器複製到另一臺服務器,但最終出現「未安裝Integration Services組件或者您沒有權限使用它「錯誤。 兩個服務器具有SQL Server 2005,並安裝了集成服務組件的企業版,連接登錄具有完全權限也是如此。我真的不知道哪裏出了問題這裏使用c將數據庫從一臺服務器複製到另一臺服務器#
Server backFromServer = new Server(@"xx.xx.xx.xx");
Server backToServer = new Server(@"xx.xx.xx.xx");
backFromServer.ConnectionContext.LoginSecure = false;
backFromServer.ConnectionContext.Login = "username";
backFromServer.ConnectionContext.Password = "password";
backToServer.ConnectionContext.LoginSecure = false;
backToServer.ConnectionContext.Login = "username";
backToServer.ConnectionContext.Password = "password";
Database backFromDb = new Database();
backFromDb = backFromServer.Databases["databasesource"];
Database backToDb = new Database();
backToDb = backToServer.Databases["databasedest"];
EventLog.WriteEntry(eventLogSource,"Loading databases successful!", EventLogEntryType.Information);
Transfer dataTransfer = new Transfer(backFromDb);
dataTransfer.CopyAllTables = true;
dataTransfer.CopyAllObjects = false;
dataTransfer.CopyData = true;
dataTransfer.CopyAllUserDefinedDataTypes = true;
dataTransfer.CopyAllStoredProcedures = false;
dataTransfer.DropDestinationObjectsFirst = true;
dataTransfer.Options.WithDependencies = false;
dataTransfer.DestinationServer = backToServer.Name;
dataTransfer.DestinationDatabase = backToDb.Name;
dataTransfer.DestinationLoginSecure = false;
dataTransfer.DestinationLogin = "username";
dataTransfer.DestinationPassword = "password";
EventLog.WriteEntry(eventLogSource,"Transfer configuration successful, starting to transfer!", EventLogEntryType.Information);
dataTransfer.TransferData();//here causes the error
EventLog.WriteEntry(eventLogSource, "Transfer successful!", EventLogEntryType.Information);
我設法找到一個解決方案 因此應用程序做到這一點: 步驟1備份數據庫到.bak文件使用備份類
Server backFromServer = new Server(@"server");
backFromServer.ConnectionContext.LoginSecure = false;
backFromServer.ConnectionContext.Login = "un";
backFromServer.ConnectionContext.Password = "psd";
Database backFromDb = new Database();
backFromDb = backFromServer.Databases["dbname"];
Backup bkpDatabase = new Backup();
bkpDatabase.Action = BackupActionType.Database;
bkpDatabase.Database = backFromDb.Name;
bkpDatabase.Incremental = false;
bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;
bkpDatabase.Initialize = true;
BackupDeviceItem bkpDevice = new BackupDeviceItem(@"c:\backup.bak", DeviceType.File);
bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackup(backFromServer);
EventLog.WriteEntry(eventLogSource, "Create database backup file successful!", EventLogEntryType.Information);
第2步。由於該文件位於源服務器中,請下載該文件。 第3步。使用t-sql恢復數據庫。 第4步。啓動每天運行應用程序的計劃任務。 這裏是T-SQL腳本: USE主 ALTER DATABASE爲[dbname] WITH回滾立即 SET SINGLE_USER RESTORE DATABASE爲[dbname] FROM DISK = N'filepath」替換,FILE = 1,NOUNLOAD,STATS = 10 ALTER DATABASE [DBName] SET Multi_User
爲什麼你會使用這個VS本地SQL Server備份/恢復工具? – 2011-01-18 22:05:00
我不熟悉SQL Server備份/恢復工具,我想在這裏完成的備份每天到另一個遠程服務器上的特定數據庫。會sql服務器備份/恢復工具滿足需要? – walter 2011-01-18 22:14:14
是的,這正是備份/恢復功能的作用。如果您考慮一下,則您正在使用與其相同的Integration Service「對象」。你基本上正在爲它寫一個新的前端。 – Tony 2011-01-18 22:48:52