SQL Server SMO TransferData() 不断失败
我正在使用 SQL Server SMO 中传输类的 TransferData 方法。 我的呼叫在 Windows XP 上运行,运行 SQL Server 2008 SP1,尝试将表从另一台服务器上的 SQL Server 2000 传输到 XP 计算机。 他们都使用相同的 SQL 用户名和密码。 我已经使用导入/导出向导进行了测试,它运行良好。
异常如下,事件日志中有一个条目“Package“ShellPackage”失败”错误。
异常错误将查询属性显示为空白并且没有替换 。 我假设 DTS 的某些部分失败了,但我不确定是哪个以及为什么。
例外: “错误:错误代码=-1073548784 描述=执行查询\”\”失败,并出现以下错误:\“'' 的类型初始值设定项引发异常。\”。可能的失败原因:查询、\“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);
}
I am using the TransferData method of the transfer class in SQL Server SMO.
I have the call running on Windows XP, running SQL Server 2008 SP1, trying to transfer a table from SQL Server 2000 on another server to the XP machine. They both use the same SQL username and password. I have tested using the Import/Export Wizard and it ran fine.
The Exception is below and the event log has an entry "Package "ShellPackage" failed" error.
The exception error shows the query property as blank and no substitution for . I am assuming some DTS piece is failing but I am not sure which and why.
Exception:
"ERROR : errorCode=-1073548784 description=Executing the query \"\" failed with the following error: \"The type initializer for '' threw an exception.\". Possible failure reasons: Problems with the query, \"ResultSet\" property not set correctly, parameters not set correctly, or connection not established correctly.\r\n helpFile= helpContext=0 idofInterfaceWithError={C81DFC5A-3B22-4DA3-BD3B-10BF861A7F9C}"
My Code:
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
托管 WCF 服务(上面的代码)的服务需要在域用户下运行。
The service hosting the WCF service (code above) needed to run under a domain user.