Problème d'adaptation sous SSIS 2k5

Bridaine Messages postés 3 Date d'inscription mercredi 3 juin 2009 Statut Membre Dernière intervention 20 janvier 2010 - 19 janv. 2010 à 16:19
Bridaine Messages postés 3 Date d'inscription mercredi 3 juin 2009 Statut Membre Dernière intervention 20 janvier 2010 - 20 janv. 2010 à 14:15
Besoin de VB pour Script sur SSIS 2k5
************************

Bonjour,

J'ai finalement trouvé un spécialiste VB pour m'aider à écrire mon script mais ça plante.

La procédure a été écrite pour une lecture séquentielle de fichier et j'ai du l'adapter à SSIS.

Voici l'objet du délit:
d'abord l'original :
'---
Option Explicit
'---
Const vGlo_Read = 1
Const vGlo_Writ = 2
'---
Dim vLoc_Cpte
Dim vLoc_Ecri
Dim vLoc_Lign
Dim vLoc_LigP
Dim vLoc_OFSO
Dim vLoc_Posi
Dim vLoc_ReaF
Dim vLoc_ReaO
Dim vLoc_Text
Dim vLoc_WriF
Dim vLoc_WriO
'---
Set vLoc_OFSO = CreateObject("Scripting.FileSystemObject")
'---
vLoc_ReaF = "C:\Users\Thierry\TRI\cls0_brokerlog.log"


vLoc_WriF = "C:\Users\Thierry\TRI\Ctre_Rendu_cls0_brokerlog.txt"
'---


Set vLoc_WriO = vLoc_OFSO.OpenTextFile(vLoc_WriF, vGlo_Writ, True)
'---
If vLoc_OFSO.FileExists(vLoc_ReaF) = True Then
Set vLoc_ReaO = vLoc_OFSO.OpenTextFile(vLoc_ReaF, vGlo_Read)
While vLoc_ReaO.AtEndOfStream <> True
vLoc_Lign = vLoc_ReaO.ReadLine
vLoc_Cpte = VLoc_Cpte + 1
vLoc_LigP = 0
vLoc_Posi = InStr(1, vLoc_Lign, "computer")


If vLoc_Posi > 0 then
vLoc_Text = Rech(vLoc_Lign, vLoc_Cpte, vLoc_LigP, vLoc_Posi, "computer")
vLoc_WriO.WriteLine(vLoc_Text)
vLoc_LigP = vLoc_LigP + 1
End If
vLoc_Posi = InStr(1, vLoc_Lign, "datasource")


If vLoc_Posi > 0 then
vLoc_Text = Rech(vLoc_Lign, vLoc_Cpte, vLoc_LigP, vLoc_Posi, "datasource")
vLoc_WriO.WriteLine(vLoc_Text)
vLoc_LigP = vLoc_LigP + 1
End If
vLoc_Posi = InStr(1, vLoc_Lign, "server")
vLoc_Ecri = False


If vLoc_Posi > 0 then
vLoc_Text = Rech(vLoc_Lign, vLoc_Cpte, vLoc_LigP, vLoc_Posi, "server")
If Veri(vLoc_Text, "has")      "Oui" Then vLoc_Ecri True
If Veri(vLoc_Text, "on")       "Oui" Then vLoc_Ecri True
If Veri(vLoc_Text, "returned") "Oui" Then vLoc_Ecri True
If Veri(vLoc_Text, "started")  "Oui" Then vLoc_Ecri True
If Veri(vLoc_Text, "to")       "Oui" Then vLoc_Ecri True
If vLoc_Ecri                   = False Then vLoc_WriO.WriteLine(vLoc_Text)
End If
Wend
vLoc_ReaO.Close
End If
'---
vLoc_WriO.Close
'---
Set vLoc_Cpte = Nothing
Set vLoc_Ecri = Nothing
Set vLoc_Lign = Nothing
Set vLoc_LigP = Nothing
Set vLoc_OFSO = Nothing
Set vLoc_Posi = Nothing
Set vLoc_ReaF = Nothing
Set vLoc_ReaO = Nothing
Set vLoc_Text = Nothing
Set vLoc_WriF = Nothing
Set vLoc_WriO = Nothing
'---
Function Rech(ByRef vLoc_Lign, ByRef vLoc_Cpte, ByRef vLoc_LigP, ByRef vLoc_Posi, ByRef vLoc_Mot)
Dim vLoc_Cpt1
Dim vLoc_Date
Dim vLoc_Pos1
Dim vLoc_Tex1
'---
vLoc_Cpt1 Right("00000000" & vLoc_Cpte, 8) & " "
vLoc_Date Left(vLoc_Lign, 17) & " "
vLoc_Tex1 = Mid(vLoc_Lign, vLoc_Posi + Len(vLoc_Mot) + 1)
If Right(vLoc_Tex1, 1) = "." Then
vLoc_Tex1 = Left(vLoc_Tex1, Len(vLoc_Tex1) - 1)
End If
vLoc_Pos1 = InStr(1, vLoc_Tex1, " ")
If vLoc_Pos1 > 0 then


vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
End If
vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
If vLoc_Pos1 = 1 then
vLoc_Tex1 = Right(vLoc_Tex1, Len(vLoc_Tex1) - 1)
End If
vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
If vLoc_Pos1 > 0 then
vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
End If
vLoc_Pos1 = InStr(1, vLoc_Tex1, "&")
If vLoc_Pos1 > 0 then
vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
End If
vLoc_Mot = Left(vLoc_Mot & Space(10), 10)
If vLoc_LigP > 0 Then
Rech Space(Len(vLoc_Cpt1 & vLoc_Date)) & vLoc_Mot & " " & vLoc_Tex1
Else
Rech vLoc_Cpt1 & vLoc_Date & vLoc_Mot & " " & vLoc_Tex1
End If
'---
Set vLoc_Cpt1 = Nothing
Set vLoc_Date = Nothing
Set vLoc_Pos1 = Nothing
Set vLoc_Tex1 = Nothing
End Function
'---
Function Veri(ByRef vLoc_Text, ByRef vLoc_Mot)
If Right(vLoc_Text, Len(vLoc_Mot)) = vLoc_Mot Then
Veri = "Oui"
Else
Veri = "Non"
End If
End Function




ensuite mon adaptation

'-----------------------------------------------------------------------------
? VERSION ADAPTEE SSIS
'-----------------------------------------------------------------------------

' Microsoft SQL Server Integration Services user script component
' This is your new script component in Microsoft Visual Basic .NET
' ScriptMain is the entrypoint class for script components

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        '
        ' Add your code here		Couleur commentaires (111, 150, 0)
        '
        '-----------------------------------------------------------------------------
        '  Traitement de recherche du mot-clé computer pour trouver le nom d'un serveur
        '-----------------------------------------------------------------------------

        Dim vLoc_Lign As String     'vLoc_Lign = récupération de la ligne en cours
        Dim vLoc_LigP As Integer    'vLoc_LigP = compteur de positionnement dans la ligne
        Dim vLoc_Posi As Integer    'vLoc_Posi = index de position dans la ligne
        Dim vLoc_Text As String     'vLoc_Text = récupération de l'occurrence transformée
        Dim vLoc_Mot As String      'vLoc_Mot = mot-clé pour recherche valeur

        '-----------------------------------------------------------------------------
        'Positionnement sur le champ contenant « computer » 
        'Appel de la fonction Rech pour récupérer la valeur associée
        '-----------------------------------------------------------------------------

        vLoc_Lign = Row.LServeur

        'vLoc_Text = "SGSI2KSIFAPP12"

        vLoc_Posi = InStr(1, vLoc_Lign, "computer")

       If vLoc_Posi > 0 Then
          vLoc_Text = CStr(Rech(vLoc_Lign, vLoc_LigP, vLoc_Posi, "computer"))
          Row.BServeur = vLoc_Text
          vLoc_LigP = vLoc_LigP + 1
        End If

        vLoc_Lign = Nothing
        vLoc_LigP = Nothing
        vLoc_Posi = Nothing
        vLoc_Text = Nothing

    End Sub

    '-----------------------------------------------------------------------------
    'Fonction Rech : elle permet la recherche d'une chaîne de caractères 
    ' mais aussi l'élimination des caractères superflus 
    ' comme les cottes, les guillemets et autres joyeusetés 
    '-----------------------------------------------------------------------------

    Function Rech(ByRef vLoc_Lign As String, ByRef vLoc_LigP As Integer, ByRef vLoc_Posi As Integer, ByRef vLoc_Mot As String) As String

        Dim vLoc_Date As String   'vLoc_Date = récup Date+ Heure (17 prem.caract)
        Dim vLoc_Pos1 As Integer  'vLoc_Lign = récup index du mot-clé
        Dim vLoc_Tex1 As String   'vLoc_Lign = valeur à récupérer

        '-----------------------------------------------------------------------------
        ' La fonction Right( ) donne les N caractères les plus à droite dans une chaine
        'Right(chaine, N)	 exp:  Right ("abcdefg", 3)	donne «efg"
        '
        ' La fonction Left( ) donne les N caractères les plus à gauche dans une chaine
        'Left(chaine, N)	 exp:  Left ("abcdefg", 3)	donne «abc"
        '-----------------------------------------------------------------------------

        vLoc_Date Left(CStr(vLoc_Lign), 17) & " "
        '-----------------------------------------------------------------------------
        ' La fonction Len(string | varname) 
        'Renvoie le nombre de caractères d'une chaîne de caractères   Len(string)
        'ou le nombre d'octets nécessaires pour stocker une variable  Len(varname)
        '-----------------------------------------------------------------------------
        'vLoc_Tex1 = Mid(vLoc_Lign, CInt((CStr(vLoc_Posi + Len(vLoc_Mot) + 1))))
        vLoc_Tex1 = Mid(vLoc_Lign, CInt(vLoc_Posi + Len(vLoc_Mot) + 1))
        If Right(vLoc_Tex1, 1) = "." Then
            vLoc_Tex1 = Left(vLoc_Tex1, Len(vLoc_Tex1) - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport aux points
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, " ")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport aux guillemets éventuels à droite et à gauche
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
        If vLoc_Pos1 = 1 Then
            vLoc_Tex1 = Right(vLoc_Tex1, Len(vLoc_Tex1) - 1)
        End If
        vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport à une esperluette à gauche	«&computer», «&datasource»
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, "&")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Résultat à renvoyer : Date+Heure mot-clé valeur
        '-----------------------------------------------------------------------------
        vLoc_Mot = Left(vLoc_Mot & Space(10), 10)
        If vLoc_LigP > 0 Then
            Rech Len(vLoc_Date) & vLoc_Mot & " " & vLoc_Tex1
        Else
            Rech vLoc_Date & vLoc_Mot & " " & vLoc_Tex1
        End If

        vLoc_Date = Nothing
        vLoc_Pos1 = Nothing
        vLoc_Tex1 = Nothing

    End Function

End Class


ENFIN, les messages d'erreur :
   at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.SetString(Int32 columnIndex, String value)
   at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.set_Item(Int32 columnIndex, Object value)
   at Microsoft.SqlServer.Dts.Pipeline.ScriptBuffer.set_Item(Int32 ColumnIndex, Object value)
   at ScriptComponent_7c05211e879443cb9cdcbe227f0999c6.Input0Buffer.set_BServeur(String Value)
   at ScriptComponent_7c05211e879443cb9cdcbe227f0999c6.ScriptMain.Input0_ProcessInputRow(Input0Buffer Row)
   at ScriptComponent_7c05211e879443cb9cdcbe227f0999c6.UserComponent.Input0_ProcessInput(Input0Buffer Buffer)
   at ScriptComponent_7c05211e879443cb9cdcbe227f0999c6.UserComponent.ProcessInput(Int32 InputID, PipelineBuffer Buffer)
   at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)


J'ai du caster un maximum car ça n'est pas fait implicitement en Vb.Net sous SSIS
Le problème doit venir de là !

...du moins je le pense

J'ai essayé d'utiliser le while au début mais
AtEndOfStream et AtEndOfLine sont refusés...

Merci de m'aider
A voir également:

3 réponses

nhervagault Messages postés 6063 Date d'inscription dimanche 13 avril 2003 Statut Membre Dernière intervention 15 juillet 2011 37
19 janv. 2010 à 20:53
Salut,

Elle est ou la gestion de ta boucle

et l'erreur n'est pas emplicite
peux-tu mettre le début de la Pile

Ensuite il serait plus facile de lire
le code en .net

Len(vLoc_Date) --> vLoc_Date.Length
Instr --> Contains


pour la gestion des filles voir les IO de vb.net

http://plasserre.developpez.com/cours/vb-net/
0
Bridaine Messages postés 3 Date d'inscription mercredi 3 juin 2009 Statut Membre Dernière intervention 20 janvier 2010
20 janv. 2010 à 10:46
Besoin de VB pour Script sur SSIS 2k5
************************

Bonjour,

Merci d'avoir pris le temps de lire tout ça avant de livrer ton analyse.

_1 En ce qui concerne la gestion de la boucle (donc le while) , comme je l'ai mentionné elle me pose un problème car SSIS ne reconnait ni AtEndOfStream ni AtEndOfLine, je ne sais pas comment l'adapter.
Ce dont j'ai surtout besoin c'est de lire ma ligne courante à chaque fois pas le fichier en entier comme dans le modèle

_2 L'Option Explicit n'est pas acceptée non plus dans SSIS

De plus, j'ai du rajouter des casts et des déclarations (As String, As Integer) parce que le compilateur VB.net de SSIS l'exige alors que ça n'est pas nécessaire dans le modèle d'origine.

_3 Le code en .net ? Malheureusement je ne maîtrise assez le sujet pour savoir comment procéder.

_4 la gestion des files et des IO ; il faut bien comprendre mon problème, le programme de mon collègue est un balayage séquentiel de fichier en VB avec effectivement des IO, mais le mien est un script component VB inclus dans un package SSIS qui se déroule pendant l'exécution de ma procédure.

Dans mon écran de saisie, j'ai du déclarer l'entrée et la sortie du script component,
_ soit le champ contenant le fragment de ligne courante en entrée LServeur
_ soit le champ contenant la valeur que je récupère en sortie BServeur

J'avais d'abord testé la procédure sans la boucle ni la fonction avec une affectation en dur et ça marchait jusque là

En résumé : comment adapter ma boucle et mes casts ?
Bonne journée
0
Bridaine Messages postés 3 Date d'inscription mercredi 3 juin 2009 Statut Membre Dernière intervention 20 janvier 2010
20 janv. 2010 à 14:15
SOLUTION
*********

Bonjour,

J'ai trouvé la solution ce matin, voilà qui pourra resservir

' Microsoft SQL Server Integration Services user script component
' This is your new script component in Microsoft Visual Basic .NET
' ScriptMain is the entrypoint class for script components

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        '
        ' Add your code here		Couleur commentaires (111, 150, 0)
        '
        '-----------------------------------------------------------------------------
        '  Traitement de recherche du mot-clé computer pour trouver le nom d'un serveur
        '-----------------------------------------------------------------------------

        Dim vLoc_Lign As String     'vLoc_Lign = récupération de la ligne en cours
        Dim vLoc_LigP As Integer    'vLoc_LigP = compteur de positionnement dans la ligne
        Dim vLoc_Posi As Integer    'vLoc_Posi = index de position dans la ligne
        Dim vLoc_Text As String     'vLoc_Text = récupération de l'occurrence transformée
        Dim vLoc_Mot As String      'vLoc_Mot = mot-clé pour recherche valeur

        '-----------------------------------------------------------------------------
        'Positionnement sur le champ contenant « computer » 
        'Appel de la fonction Rech pour récupérer la valeur associée
        '-----------------------------------------------------------------------------

        vLoc_Lign = Row.LServeur

        'vLoc_Text = "SGSI2KSIFAPP12"
        'Row.BServeur = vLoc_Text

        Row.BServeur = " "

        While vLoc_LigP < 251
            vLoc_Posi = InStr(1, vLoc_Lign, "computer")
            If vLoc_Posi > 0 Then
                '          vLoc_Text = CStr(Rech(vLoc_Lign, vLoc_LigP, vLoc_Posi, "computer"))
                vLoc_Text = Rech(vLoc_Lign, vLoc_LigP, vLoc_Posi, "computer")

                If Mid(vLoc_Text, 1, 8) = "computer" Then
                    vLoc_LigP = 251
                End If
                Row.BServeur = Mid(vLoc_Text, 11)

                vLoc_LigP = vLoc_LigP + 1
            End If
        End While

        vLoc_Lign = Nothing
        vLoc_LigP = Nothing
        vLoc_Posi = Nothing
        vLoc_Text = Nothing

    End Sub

    '-----------------------------------------------------------------------------
    'Fonction Rech : elle permet la recherche d'une chaîne de caractères 
    ' mais aussi l'élimination des caractères superflus 
    ' comme les cottes, les guillemets et autres joyeusetés 
    '-----------------------------------------------------------------------------

    Function Rech(ByRef vLoc_Lign As String, ByRef vLoc_LigP As Integer, ByRef vLoc_Posi As Integer, ByRef vLoc_Mot As String) As String

        Dim vLoc_Date As String   'vLoc_Date = récup Date+ Heure (17 prem.caract)
        Dim vLoc_Pos1 As Integer  'vLoc_Lign = récup index du mot-clé
        Dim vLoc_Tex1 As String   'vLoc_Lign = valeur à récupérer

        '-----------------------------------------------------------------------------
        ' La fonction Right( ) donne les N caractères les plus à droite dans une chaine
        'Right(chaine, N)	 exp:  Right ("abcdefg", 3)	donne «efg"
        '
        ' La fonction Left( ) donne les N caractères les plus à gauche dans une chaine
        'Left(chaine, N)	 exp:  Left ("abcdefg", 3)	donne «abc"
        '-----------------------------------------------------------------------------
        'vLoc_Date Left(CStr(vLoc_Lign), 17) & " "

        vLoc_Date Left(vLoc_Lign, 17) & " "
        '-----------------------------------------------------------------------------
        ' La fonction Len(string | varname) 
        'Renvoie le nombre de caractères d'une chaîne de caractères   Len(string)
        'ou le nombre d'octets nécessaires pour stocker une variable  Len(varname)
        '-----------------------------------------------------------------------------
        'vLoc_Tex1 = Mid(vLoc_Lign, CInt((CStr(vLoc_Posi + Len(vLoc_Mot) + 1))))
        'vLoc_Tex1 = Mid(vLoc_Lign, CInt(vLoc_Posi + Len(vLoc_Mot) + 1))

        vLoc_Tex1 = Mid(vLoc_Lign, vLoc_Posi + Len(vLoc_Mot) + 1)
        If Right(vLoc_Tex1, 1) = "." Then
            vLoc_Tex1 = Left(vLoc_Tex1, Len(vLoc_Tex1) - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport aux points
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, " ")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport aux guillemets éventuels à droite et à gauche
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
        If vLoc_Pos1 = 1 Then
            vLoc_Tex1 = Right(vLoc_Tex1, Len(vLoc_Tex1) - 1)
        End If
        vLoc_Pos1 = InStr(1, vLoc_Tex1, """")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Position par rapport à une esperluette à gauche	«&computer», «&datasource»
        '-----------------------------------------------------------------------------
        vLoc_Pos1 = InStr(1, vLoc_Tex1, "&")
        If vLoc_Pos1 > 0 Then
            vLoc_Tex1 = Left(vLoc_Tex1, vLoc_Pos1 - 1)
        End If
        '-----------------------------------------------------------------------------
        ' Résultat à renvoyer : "computer = " valeur
        '-----------------------------------------------------------------------------
        'vLoc_Mot = Left(vLoc_Mot & Space(10), 10)
        'If vLoc_LigP > 0 Then
        '   Rech Len(vLoc_Date) & vLoc_Mot & " " & vLoc_Tex1
        'Else
        '   Rech vLoc_Date & vLoc_Mot & " " & vLoc_Tex1
        'End If

        Rech vLoc_Mot & " " & vLoc_Tex1

        vLoc_Date = Nothing
        vLoc_Pos1 = Nothing
        vLoc_Tex1 = Nothing

    End Function


End Class


Commentaires :

1_ Il fallait refaire la boucle avec un compteur numérique (si jamais il s'avérait trop grand, je pourrais toujours le diminuer 250, 249...)

2_ Les casts m'avaient été imposés par le compilateur avant que je ne type avec les As, du coup il y avait surenchère
Plus besoin de casts avec des déclarations As Integer, As String, etc...en amont

3_ Il ne restait plus qu'à aménager la fin de la fonction pour récupérer mes billes (ici le serveur, je n'ai pu qu'à faire la même moulinette pour la datasource)


Je pousse un gros OUF !
0
Rejoignez-nous