これは古い投稿であり、SSISやSSDTとは何の関係もないことは知っていますが、OPは利用可能な他のオプションについて問い合わせているようです。そのため、これらのツールを使用せずに抽出ファイルをインポートする簡単な方法を探している人のために、これを追加したいと思いました. 抽出ファイル (CSV、Access、Excel、FoxPro など) からデータをインポートする必要がある文字通り何百ものプロセスを作成しました。以下は、Excel スプレッドシートのすべてのシートをロードしてから単純に表示する Powershell スニペットです。データグリッドのコンテンツですが、ロジックを簡単に追加して、たとえばデータをテーブルにインポートできるはずです。建設的な批判はいつでも大歓迎です!
Clear-Host;
## You May Need to Download and Install the Microsoft Access Database Engine 2010 Redistributable: https://www.microsoft.com/en-us/download/details.aspx?id=13255
[String]$ExcelPath = "C:\Temp\TestSheet.xlsx";
[String]$TargetServer = "(local)";
[String]$TargetDatabase = "TestDB";
[String]$SourceConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES';" -f $ExcelPath;
[String]$TargetConnectionString = "Data Source={0};Initial Catalog={1};Trusted_Connection=True;" -f $TargetServer, $TargetDatabase;
$SourceFactory = [System.Data.Common.DbProviderFactories]::GetFactory("System.Data.OleDb");
$TargetFactory = [System.Data.Common.DbProviderFactories]::GetFactory("System.Data.SqlClient");
$SourceConnection = $SourceFactory.CreateConnection();
$SourceConnection.ConnectionString = $SourceConnectionString;
$SourceConnection.Open();
$SourceCommand = New-Object $SourceFactory.CreateCommand();
$SourceCommand.Connection = $SourceConnection;
$SourceCommand.CommandTimeout = [Int32]::MaxValue;
$TargetConnection = $TargetFactory.CreateConnection();
$TargetConnection.ConnectionString = $TargetConnectionString;
$TargetConnection.Open();
$TargetCommand = New-Object $TargetFactory.CreateCommand();
$TargetCommand.Connection = $TargetConnection;
$TargetCommand.CommandTimeout = [Int32]::MaxValue;
foreach($table in $SourceConnection.GetSchema("Tables").Rows){
try{
## Source
[String]$TabName = $table["TABLE_NAME"];
[String]$sqlString = "SELECT * FROM [{0}];" -f $TabName;
$SourceCommand.CommandText = $sqlString;
[System.Data.Common.DbDataReader]$SourceDataReader = $SourceCommand.ExecuteReader();
$dtData = New-Object System.Data.DataTable;
$dtData.Load($SourceDataReader);
## Target -- Bulk Insert data
if($dtData.Rows.Count -gt 0){
$TabName = "[{0}]" -f $TabName;
$sqlBulkCopy = New-Object System.Data.SqlClient.SqlBulkCopy($TargetConnection);
$sqlBulkCopy.DestinationTableName = $TabName;
foreach ($Column in $dtData.Columns){
$sqlBulkCopy.ColumnMappings.Add($column, $column)
};
$sqlBulkCopy.WriteToServer($dtData);
}
}catch{
$table["TABLE_NAME"];
$_.Exception.Message;
$_.Exception.ItemName;
};
};
#Housekeeping
$sqlBulkCopy.Close();
$sqlBulkCopy.Dispose();
$SourceCommand.Dispose();
$SourceDataReader.Dispose();
$SourceConnection.Close();
$SourceConnection.Dispose();
$TargetCommand.Dispose();
$TargetDataReader.Dispose();
$TargetConnection.Close();
$TargetConnection.Dispose();
$TargetConnection.Close();
$TargetConnection.Dispose();
[System.GC]::Collect();