Oppure

Loading
22/04/22 13:17
donatella72
Salve,
sono nuova del forum non so se ho postato nel posto giusto.
Devo spostare file xls dalla directory di un server in un'altra directory di un altro server. Vorrei usare dispose()
per le risorse da rilasciare, perché il file sembra rimanere in uso, ma non so come.
Sono un principiante. Questo il mio codice:

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic 2008.
' The ScriptMain is the entry point class of the script.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
    Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

    Enum ScriptResults
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    End Enum

    ' The execution engine calls this method when the task executes.
    ' To access the object model, use the Dts property. Connections, variables, events,
    ' and logging features are available as members of the Dts property as shown in the following examples.
    '
    ' To reference a variable, call Dts.Variables("MyCaseSensitiveVariableName").Value
    ' To post a log entry, call Dts.Log("This is my log text", 999, Nothing)
    ' To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, True)
    '
    ' To use the connections collection use something like the following:
    ' ConnectionManager cm = Dts.Connections.Add("OLEDB")
    ' cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"
    '
    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    ' 
    ' To open Help, press F1.

    Dim NomefileDestinazione, NomeFilesorgente As String


    Public Sub Main()
        '
        ' Add your code here
        '
        NomeFilesorgente = "\servername1\DirectoryName\testing.xls"
        NomefileDestinazione = "\servername2\DirectoryName\" & Dts.Variables("NomeFilexls").Value.ToString & "_Parte" & Dts.Variables("j").Value.ToString & ".xls"
        My.Computer.FileSystem.MoveFile(NomeFilesorgente, NomefileDestinazione, True)
        Dts.Variables("j").Value = CInt(Dts.Variables("j").Value.ToString) + 1

        Dts.TaskResult = ScriptResults.Success
    End Sub

End Class



Uso questo codice in un task SSIS ed esattamente nel task For Loop Container .

Vi ringrazio per l'aiuto.
Ultima modifica effettuata da Thejuster 22/04/22 14:27
22/04/22 14:34
Thejuster
Ciao,
usa sempre il tag code per il codice altrimenti diventa incompresibile.



 NomeFilesorgente = "\servername1\DirectoryName\testing.xls"
        NomefileDestinazione = "\servername2\DirectoryName\" & Dts.Variables("NomeFilexls").Value.ToString & "_Parte" & Dts.Variables("j").Value.ToString & ".xls"
        My.Computer.FileSystem.MoveFile(NomeFilesorgente, NomefileDestinazione, True)




NomeFilesorgente = "\servername1\DirectoryName\testing.xls"

Devi specificare un indirizzo fisico di dove è siutato il file.

un esempio è:
Copia da C:\testo.txt in \ufficio\cartella\testo.txt

nel tuo esempio e come se un terzo computer chiederebbe di copiare un file dal 1 terminale al secondo terminale.

mire.forumfree.it/ - Mire Engine
C# UI Designer