How to Import text file using SMO/SSIS

  • How to import a text/flat file data to sql server using smo/ssis libraries?

  • This was removed by the editor as SPAM

  • If your text file is in a regular layout, you can use the SSIS flat file connection manager to import the files content into the data flow.

    If the text file has a more complicated layout, you can use the script component as your data source (see SSIS - Using a Script Component as a Source). Open the text file using a text stream. Here is a quick code sample.

    Imports System.IO

    ...

    Dim textReader As StreamReader

    Dim fInfo As FileInfo

    fInfo = new FileInfo(Path.Combine("c:\mydir", "myfile.txt"))

    if fInfo.Exists then

    textReader = New StreamReader(file.FullName)

    nextLine = textReader.ReadLine

    Do While nextLine IsNot Nothing ' process each line in the file

    ... do your processing here on each line

    nextLine = textReader.ReadLine

    Loop

    textReader.Close()

    end if

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply