dbTalk Databases Forums  

Code to import text with DTS

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Code to import text with DTS in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
fabian
 
Posts: n/a

Default Code to import text with DTS - 02-16-2004 , 06:07 AM






Hi, I've got this code:

dim pkg As DTS.Package

pkg = New DTS.Package

Dim oconn As DTS.Connection

Dim v As String


pkg.LoadFromSQLServer("server", "sa", "sa", _

DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, _

"", "", "", "ImportText", Nothing)

oconn = pkg.Connections.Item("Texto")

oconn.DataSource = "c:\bcp.txt"

pkg.Execute()



The code seems correct because it doesn't throw any exception but it doesn't
import any data to the table. Is there anything wrong?



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Code to import text with DTS - 02-16-2004 , 06:45 AM






Set the package to fail on first error

This code works for me and raises the following error if the file does not
exist

Step 'DTSStep_DTSDataPumpTask_1' failed

Step Error Source: Microsoft Data Transformation Services Flat File Rowset
Provider
Step Error Description:Error opening datafile: The system cannot find the
file specified.


Code:

Try

dtsPackage = New DTS.Package

dtsPackage.LoadFromSQLServer("LocalServer", , ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , ,
"ChangeTextFileSourceName")

con = dtsPackage.Connections.Item("TextFileSource")

con.DataSource = Me.txtTextFileConnectionName.Text

'Fail on first error

dtsPackage.FailOnError = True

dtsPackage.Execute()

dtsPackage.UnInitialize()

Catch eX As Exception

MessageBox.Show("Exception raised in calling package: " & eX.Message)

End Try


--

----------------------------

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"fabian" <fabianbg (AT) navegalia (DOT) com> wrote

Quote:
Hi, I've got this code:

dim pkg As DTS.Package

pkg = New DTS.Package

Dim oconn As DTS.Connection

Dim v As String


pkg.LoadFromSQLServer("server", "sa", "sa", _

DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, _

"", "", "", "ImportText", Nothing)

oconn = pkg.Connections.Item("Texto")

oconn.DataSource = "c:\bcp.txt"

pkg.Execute()



The code seems correct because it doesn't throw any exception but it
doesn't
import any data to the table. Is there anything wrong?





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.