我在SQL Server SMO中使用传输类的TransferData方法。 我在Windows XP上运行调用,运行SQL Server 2008 SP1,尝试将表从另一台服务器上的SQL Server 2000传输到XP机器。它们都使用相同的SQL用户名和密码。我已经使用导入/导出向导进行了测试,运行正常。
下面是异常,事件日志中有一个条目“Package”ShellPackage“failed”错误。
异常错误将查询属性显示为空白且不替换。我假设某些DTS片段失败但我不确定哪个和为什么。
例外: “错误: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);
}
答案 0 :(得分:0)
托管WCF服务的服务(上面的代码)需要在域用户下运行。