IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SSIS Discussion :

Lecture de fichier en VB avec SSIS


Sujet :

SSIS

  1. #1
    Membre à l'essai
    Homme Profil pro
    Chef d'entreprise
    Inscrit en
    Février 2016
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef d'entreprise

    Informations forums :
    Inscription : Février 2016
    Messages : 23
    Points : 20
    Points
    20
    Par défaut Lecture de fichier en VB avec SSIS
    Bonjour à tous,

    voici mon problème : je dois intégrer un fichier tous les matins avec des données texte. Or ce fichier m'est fourni avec un caractère de fin de ligne Windows (CR+LF). J'ai besoin pour que les données soient bien insérées dans ma base de convertir ce caractère de fin en Linux (LF)

    Or j'ai essayé une tache de script avec le code ci dessous
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    #Region "Help:  Introduction to the script task"
    'The Script Task allows you to perform virtually any operation that can be accomplished in
    'a .Net application within the context of an Integration Services control flow. 
     
    'Expand the other regions which have "Help" prefixes for examples of specific ways to use
    'Integration Services features within this script task.
    #End Region
     
     
    #Region "Imports"
    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Runtime
    #End Region
     
    'ScriptMain is the entry point class of the script.  Do not change the name, attributes,
    'or parent of this class.
    <Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()> _
    <System.CLSCompliantAttribute(False)> _
    Partial Public Class ScriptMain
        Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
     
    #Region "Help:  Using Integration Services variables and parameters in a script"
        'To use a variable in this script, first ensure that the variable has been added to 
        'either the list contained in the ReadOnlyVariables property or the list contained in 
        'the ReadWriteVariables property of this script task, according to whether or not your
        'code needs to write to the variable.  To add the variable, save this script, close this instance of
        'Visual Studio, and update the ReadOnlyVariables and 
        'ReadWriteVariables properties in the Script Transformation Editor window.
        'To use a parameter in this script, follow the same steps. Parameters are always read-only.
     
        'Example of reading from a variable:
        ' startTime = Dts.Variables("System::StartTime").Value
     
        'Example of writing to a variable:
        ' Dts.Variables("User::myStringVariable").Value = "new value"
     
        'Example of reading from a package parameter:
        ' batchId = Dts.Variables("$Package::batchId").Value
     
        'Example of reading from a project parameter:
        ' batchId = Dts.Variables("$Project::batchId").Value
     
        'Example of reading from a sensitive project parameter:
        ' batchId = Dts.Variables("$Project::batchId").GetSensitiveValue()
    #End Region
     
    #Region "Help:  Firing Integration Services events from a script"
        'This script task can fire events for logging purposes.
     
        'Example of firing an error event:
        ' Dts.Events.FireError(18, "Process Values", "Bad value", "", 0)
     
        'Example of firing an information event:
        ' Dts.Events.FireInformation(3, "Process Values", "Processing has started", "", 0, fireAgain)
     
        'Example of firing a warning event:
        ' Dts.Events.FireWarning(14, "Process Values", "No values received for input", "", 0)
    #End Region
     
    #Region "Help:  Using Integration Services connection managers in a script"
        'Some types of connection managers can be used in this script task.  See the topic 
        '"Working with Connection Managers Programatically" for details.
     
        'Example of using an ADO.Net connection manager:
        ' Dim rawConnection As Object = Dts.Connections("Sales DB").AcquireConnection(Dts.Transaction)
        ' Dim myADONETConnection As SqlConnection = CType(rawConnection, SqlConnection)
        ' <Use the connection in some code here, then release the connection>
        ' Dts.Connections("Sales DB").ReleaseConnection(rawConnection)
     
        'Example of using a File connection manager
        ' Dim rawConnection As Object = Dts.Connections("Prices.zip").AcquireConnection(Dts.Transaction)
        ' Dim filePath As String = CType(rawConnection, String)
        ' <Use the connection in some code here, then release the connection>
        ' Dts.Connections("Prices.zip").ReleaseConnection(rawConnection)
    #End Region
     
        'This method is called when this script task executes in the control flow.
        'Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
        'To open Help, press F1.
     
        Public Sub Main()
            '
            ' Add your code here
            '
            Dim pk As New Package
     
     
            Dim file As New System.IO.StreamReader(Dts.Variables("@[User::varFileName]").Value.ToString())
            Dim data As String
            data = file.ReadToEnd()
            data = data.Replace(vbCrLf, vbLf)
            'data = data.Replace(vbCr, vbLf)
            'data = data.Replace(vbLf, vbCrLf)
            file.Close()
     
            Dim writer As New System.IO.StreamWriter(Dts.Variables("@[User::varFileName]").Value.ToString(), False)
            writer.Write(data)
            writer.Flush()
            writer.Close()
     
            Dts.TaskResult = ScriptResults.Success
        End Sub
     
    #Region "ScriptResults declaration"
        'This enum provides a convenient shorthand within the scope of this class for setting the
        'result of the script.
     
        'This code was generated automatically.
        Enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        End Enum
     
    #End Region
     
    End Class
    J'obtiens ce message d'erreur :
    Nom : Capture d’écran 2019-11-13 à 12.24.07.png
Affichages : 311
Taille : 46,7 Ko

    Je précise que la variable varFileName fonctionne bien car je m'en sers dans un container foreachFile. Pourriez vous m'aider.

    D'avance, merci

    Julien

  2. #2
    Membre éclairé
    Avatar de Wachter
    Homme Profil pro
    Développeur
    Inscrit en
    Octobre 2008
    Messages
    404
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Octobre 2008
    Messages : 404
    Points : 734
    Points
    734
    Par défaut
    Bonjour,

    Aurais-tu essayé de lire le fichier via un composant SSIS classique et ensuite nettoyer le contenu dans le flux de données en rajoutant une colonne dérivée ?
    REPLACE(REPLACE(ColAvecCRLF, char(13), ''), char(10), '')
    Code parrain certification Voltaire : NTMPH759

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 02/12/2016, 11h25
  2. Lecture de fichier XML généré avec SOAP
    Par Erkcy dans le forum XML/XSL et SOAP
    Réponses: 9
    Dernier message: 09/01/2008, 22h22
  3. Lecture de fichier binaire fortran avec java
    Par bigbrother737 dans le forum Langage
    Réponses: 1
    Dernier message: 11/05/2007, 10h34
  4. lecture de fichier en parametre avec fstream
    Par tcharles dans le forum SL & STL
    Réponses: 8
    Dernier message: 07/12/2005, 15h33
  5. Réponses: 12
    Dernier message: 14/06/2004, 13h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo