SQL Server Integration Services

De Banane Atomic
Aller à la navigationAller à la recherche

Présentation

Permet de:

  1. extraire des données depuis une source: fichier, base de données
  2. transformer ces données
  3. charger ces données vers une destination: fichier, base de données

SSIS est un outil ETL (Extraction Transformation and Load)

Liens

Nouveau Projet

Visual Studio → File → New → Project → Integration Services Project

Control Flow

Récupération des données.

Exécuter du code SQL

Execute SQL Task

Télécharger un fichier depuis internet

  1. Spécifier l'url du fichier à télécharger: clique-droit dans Connection Managers → New Connection → Type: HTTP
  2. Spécifier l'emplacement où télécharger le fichier: clique-droit dans Connection Managers → New File Connection
  3. Ajouter une Script Task
ScriptMain.cs
try
{
    // Logging start of download
    bool fireAgain = true;
    Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Connections["HTTP Connection Manager"].ConnectionString, string.Empty, 0, ref fireAgain);

    // Get your newly added HTTP Connection Manager
    var mySSISConnection = Dts.Connections["HTTP Connection Manager"].AcquireConnection(null);

    // Create a new connection
    var myConnection = new HttpClientConnection(mySSISConnection);

    // Download file and use the File Connectionstring to save the file
    myConnection.DownloadFile(Dts.Connections["DownloadedFile"].ConnectionString, true);

    // Logging end of download
    Dts.Events.FireInformation(0, "Download File", "Finished downloading " + Dts.Connections["DownloadedFile"].ConnectionString, string.Empty, 0, ref fireAgain);

    // Quit Script Task succesful
    Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
    // Logging why download failed
    Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, string.Empty, 0);

    // Quit Script Task unsuccesful
    Dts.TaskResult = (int)ScriptResults.Failure;
}

Data Flow

Mise en forme des données.

Fichier CSV

SSIS Toolbox Box → Other Destinations/Sources → Flat File Destination/Source

Multiple sources

Connection → MULTIFLATFILE pour plusieurs fichiers CSV ayant exactement les mêmes colonnes
Union All pour réunir des données non triées
Merge pour réunir des données triées
Merge Join pour réunir des données découpées et liées

Erreurs

Unable to bulk copy data. You may need to run this package as an administrator

Utiliser OLE DB Destination au lieu de SQL Server Destination.

Installation

  1. New SQL stand-alone installation or add features to an existing installation
  2. Instance Features → Database Engine Services
  3. Shared Features → Integration Services

Enable named pipes

  • C:\Windows\SysWOW64\SQLServerManager16.msc
  • SQL Server Network Configuration → Protocols for MSSQLSERVER
  • Named Pipes → Enabled
  • TCP/IP → Enabled

SSIS Catalog

  • SSMS → right-click on Integration Services Catalogs → Create Catalog
  • Enable CLR integration
  • Enable automatic execution of IS stored procedure at SQL Server startup

SQL Server Agent

  • Start from SSMS or Services

Visual Studio SQL Server Integration Services Extension