我正在使用SQL Server SMO中傳輸類的TransferData方法。 我在Windows XP上運行調用,運行SQL Server 2008 SP1,嘗試將另一臺服務器上的SQL Server 2000中的錶轉移到XP機器上。他們都使用相同的SQL用戶名和密碼。我使用導入/導出嚮導進行了測試,運行良好。SQL Server SMO TransferData()保持失敗
異常情況如下,事件日誌中有一個條目「Package」ShellPackage「failed」錯誤。
異常錯誤顯示查詢屬性爲空白並且沒有替換。我假設一些DTS部分失敗,但我不確定是哪一部分以及爲什麼。
異常: 「ERROR:errorCode = -1073548784 description =執行查詢\」\「失敗,出現以下錯誤:\」''的類型初始值設定項引發異常。\「。可能的失敗原因:查詢,「ResultSet」屬性設置不正確,參數設置不正確或連接未正確建立。\ r \ n helpFile = helpContext = 0 idofInterfaceWithError = {C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}「
我的代碼:
try
{
string MasterUser = ConfigurationSettings.AppSettings["SQLUserName"];
string MasterPassword = ConfigurationSettings.AppSettings["SQLPassword"];
Server server = new Server(SourceServer);
server.ConnectionContext.LoginSecure = false;
server.ConnectionContext.Login = MasterUser;
server.ConnectionContext.Password = MasterPassword;
Database databaseSource = server.Databases[SourceDatabaseName];
Transfer transfer = new Transfer(databaseSource);
transfer.CopyAllObjects = false;
transfer.DropDestinationObjectsFirst = false;
transfer.UseDestinationTransaction = true;
if (IsBasic)
{
transfer.CopyAllDefaults = false;
transfer.Options.Indexes = false;
transfer.Options.DriAll = false;
transfer.CopyAllDefaults = false;
}
else
{
transfer.CopyAllDefaults = true;
transfer.Options.Indexes = true;
transfer.Options.DriAll = true;
transfer.CopyAllDefaults = true;
}
transfer.Options.AnsiFile = true;
transfer.Options.SchemaQualify = true;
transfer.Options.WithDependencies = false;
transfer.CreateTargetDatabase = false;
transfer.CopySchema = true;
if (CopyData)
transfer.CopyData = true;
else
transfer.CopyData = false;
transfer.DestinationServer = DestinationServer;
transfer.DestinationDatabase = DestinationDatabaseName;
transfer.DestinationLoginSecure = false;
transfer.DestinationLogin = MasterUser;
transfer.DestinationPassword = MasterPassword;
//find the able object
foreach (Table table in databaseSource.Tables)
{
if (table.Name == TableName)
{
tableToTransfer = table;
break;
}
}
transfer.Options.IncludeIfNotExists = true;
transfer.ObjectList.Add(tableToTransfer);
transfer.TransferData();
}
catch (DbException dbExp)
{
throw new FaultException(dbExp.Message);
}
catch (Exception ex)
{
throw new FaultException(ex.Message);
}