2

我们有一些大型 Excel 文件(每个文件通常超过 100MB),需要定期导入 SQL Server 数据库,我正在寻找自动化此过程的选项。

听起来微软不再支持其商业智能开发工作室 (BIDS),而是用一种名为 SQL Server Data Tools - 商业智能 (SSDT-BI) 的东西取而代之。

因此,看起来我的选择是 SSDT-BI 或 SSIS 包,但我不确定使用哪一个。有人可以提供有关这两种解决方案的一些信息吗?任何有关找到此问题的解决方案的建议将不胜感激。

4

2 回答 2

0

我知道这是一篇旧帖子,它与 SSIS 或 SSDT 无关,但 OP 似乎在询问其他可能可用的选项。所以我想为那些正在寻找一种简单的方法来导入提取文件而不必使用这些工具中的任何一个的人添加这个。我已经创建了数百个进程,我需要从提取文件(CSV、Access、Excel、FoxPro 等)导入数据以下是一个 Powershell 片段,它将加载 Excel 电子表格中的所有工作表,然后简单地显示数据网格中的内容,但您应该能够轻松地添加逻辑以将数据导入表中。建设性的批评总是受欢迎的!

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();
于 2019-08-28T23:58:39.333 回答
-1

d/cb/n SSIS 和 SSDT 没有退出,但 SSIS 是 SSDT 的组成部分之一,意味着 SSDT 包含 SSIS、SSRS 和 SSAS。

于 2019-08-28T22:45:19.330 回答