想知道如何遍历SSISDB文件夹,C#

时间:2017-07-28 16:38:52

标签: c# ssis

我正在尝试用C#编写这个powershell脚本的功能(见图)。 走了一半但运气不大(我使用这些命名空间

using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer;
using Microsoft.SqlServer.Management.IntegrationServices;

) 我设法让我的代码完成了工作

SqlConnection ssisConnection = new SqlConnection(@"Data 
Source=MHPDW2;Initial Catalog=master;Integrated Security=SSPI;");

IntegrationServices ssisServer = new IntegrationServices(ssisConnection);
foreach ?? ( you continue )

但是之后没有运气如何遍历每个文件夹。 BTW powershell脚本运行正常,没有任何问题。 救命!点击下面的链接获取powershell脚本代码图片

powerscript code

$sqlConnectionString = "Data Source=MHPAPP2;Initial Catalog=master;Integrated Security=SSPI;" 
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString 



# Create the Integration Services object 
$integrationServices = New-Object $ISNamespace".IntegrationServices" $sqlConnection 

if ($integrationServices.Catalogs.Count -gt 0)  
{  
    $catalog = $integrationServices.Catalogs["SSISDB"] 

    write-host "Enumerating all folders..." 

    $folders = $catalog.Folders 

    if ($folders.Count -gt 0) 
    { 
        foreach ($folder in $folders) 
        { 
            $foldername = $folder.Name 
            Write-Host "Exporting Folder " $foldername " ..." 

            # Create a new file folder 
            mkdir $ProjectFilePath"\"$foldername 

            # Export all projects 
            $projects = $folder.Projects 
            if ($projects.Count -gt 0) 
            { 
                foreach($project in $projects) 
                { 
                    $fullpath = $ProjectFilePath + "\" + $foldername + "\" + $project.Name + ".ispac" 
                    Write-Host "Exporting to " $fullpath "  ..." 
                    [System.IO.File]::WriteAllBytes($fullpath, $project.GetProjectBytes()) 
                } 
            } 
        } 
    } 
} 

Write-Host "All done."

0 个答案:

没有答案