C#内でTaskHostオブジェクトを使用して(SSISスクリプトタスク内で使用しますが、これは一般的にC#にも当てはまるはずです)、「dbo」スキーマにないテーブルを処理するにはどうすればよいでしょうか。
基本的にソースデータベースとデスティネーションデータベースに接続し、テーブルスキーマとデータの両方の特定のテーブル(ループ内)を1つずつ移動するコードを作成しました。
私のローカルホストでは、これは非常にうまく機能しますが、私のクライアントでは、サプライヤーはスキーマを使用しています。私たちが最初に考慮したことではなく、これは私にいくつかの問題を与えています。
TaskHostオブジェクトの「SchemasList」プロパティを使用しようとしましたが、同じエラーが発生し続けます。
? child.Errors[0]
{Microsoft.SqlServer.Dts.Runtime.DtsError}
base {Microsoft.SqlServer.Dts.Runtime.DtsObject}: {Microsoft.SqlServer.Dts.Runtime.DtsError}
Description: "Table \"[theSchema].[theTable]\" does not exist at the source.\r\n"
ErrorCode: -1073548445
HelpContext: 0
HelpFile: ""
IDOfInterfaceWithError: "{B6F6D221-FC27-4F71-B5A0-597583986C28}"
Source: "{D6DF0C1F-0AC8-4748-836C-BEF052454AEE}"
SubComponent: "Transfer SQL Server Objects Task"
TimeStamp: {16-07-2012 13:41:43}
コードは次のとおりです。
if (Dts.Variables["tableName"].Value.ToString() != "0") {
string tableName;
tableName = Dts.Variables["tableName"].Value.ToString();
// Add a child package
Package child = new Package();
child.Name = tableName;
Executable moveTable = child.Executables.Add("STOCK:TransferSQLServerObjectsTask");
TaskHost moveTableTask = (TaskHost)moveTable;
// Set properties for the task
moveTableTask.Properties["CopyAllObjects"].SetValue(moveTableTask, false);
moveTableTask.Properties["CopyAllTables"].SetValue(moveTableTask, false);
moveTableTask.Properties["CopySchema"].SetValue(moveTableTask, true);
moveTableTask.Properties["DropObjectsFirst"].SetValue(moveTableTask, true);
moveTableTask.Properties["CopyData"].SetValue(moveTableTask, true);
// Set schemas
//StringCollection schemas = new StringCollection();
//String[] schemaList = new String[] {"[theSchema].[" + tableName + "]"};
//schemas.AddRange(schemaList);
//moveTableTask.Properties["SchemasList"].SetValue(moveTableTask, schemas);
// Set tablenames
StringCollection tables = new StringCollection();
tables.Add(tableName);
moveTableTask.Properties["TablesList"].SetValue(moveTableTask, tables);
// Set up connections
ConnectionManager source;
ConnectionManager destination;
source = child.Connections.Add("SMOServer");
source.ConnectionString = "SqlServerName=*****;UseWindowsAuthentication=False;UserName=*****;Password=*****;";
source.Name = "Source";
destination = child.Connections.Add("SMOServer");
destination.ConnectionString = "SqlServerName=*****;Persist Security Info=True;Password=*****;USER ID=*****;Initial Catalog=*****";
destination.Name = "Destination";
moveTableTask.Properties["SourceConnection"].SetValue(moveTableTask, "Source");
moveTableTask.Properties["SourceDatabase"].SetValue(moveTableTask, "*****");
moveTableTask.Properties["DestinationConnection"].SetValue(moveTableTask, "Destination");
moveTableTask.Properties["DestinationDatabase"].SetValue(moveTableTask, "*****");
child.Execute();
child.Dispose();
ご覧のとおり、スキーマをそのように追加できるかどうかを確認するためのコメント付きのビットがあります。私が試したもう1つのオプションは、CopyAllSchemasプロパティを使用することでしたが、それでも何も起こりませんでした。
また、テーブル名がテーブルstringcollectionに追加されるコード行にスキーマを追加しようとしましたが、角かっこ([])を使用するかどうかに関係なく、同じエラーが発生します。TaskHostは、何かが足りない場合を除いて、デフォルトでは「dbo」スキーマのテーブルのみを受け入れるようです。
TaskHostにデータベーススキーマを処理させる方法について誰かが何か考えを持っていますか?