dbTalk Databases Forums  

DTS connection & BulkInsertTask

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


Discuss DTS connection & BulkInsertTask in the microsoft.public.sqlserver.dts forum.



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

Default DTS connection & BulkInsertTask - 05-04-2004 , 11:11 AM






Hi

1. Can anyone tell me how to connect a Text File(source) as datasource through programming (not through wizard) in vb.net
2. Is the Text Qualifier property present in connectionproperties of a DTS connection? If so, is it read only or can we modify the property with any text qualifier like single quote, double quotes etc?

Please provide names of necessary com objects to add reference in the project and also syntax of the connection, task & connectionpropertie

FYI, I am using bulkInsertTask to import from a text file to a sql server 2000 table. Is there still a better way to do this job

Thanks for your help
s



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

Default Re: DTS connection & BulkInsertTask - 05-04-2004 , 01:44 PM






You need to add a ref to the DTS Package Object library

Dim p As New DTS.Package

Dim cn As DTS.Connection

p.LoadFromSQLServer(".", , ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , ,
"MyPackage")

For Each cn In p.Connections

If cn.ProviderID = "DTSFlatFile" Then 'text File

'ideally you would know the name of the connection

'What is the text qualifier property

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value)

'Now change it

cn.ConnectionProperties.Item("Text Qualifier").Value = "£"

'Have a look

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value)



End If

Next

p.UnInitialize()


--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi,

1. Can anyone tell me how to connect a Text File(source) as datasource
through programming (not through wizard) in vb.net?
2. Is the Text Qualifier property present in connectionproperties of a DTS
connection? If so, is it read only or can we modify the property with any
text qualifier like single quote, double quotes etc?
Quote:
Please provide names of necessary com objects to add reference in the
project and also syntax of the connection, task & connectionproperties

FYI, I am using bulkInsertTask to import from a text file to a sql server
2000 table. Is there still a better way to do this job?

Thanks for your help,
sp





Reply With Quote
  #3  
Old   
sp
 
Posts: n/a

Default Re: DTS connection & BulkInsertTask - 05-04-2004 , 02:21 PM



Allan, Can you explain

p.LoadFromSQLServer(".", , ,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTru stedConnection, , , ,"MyPackage"

1. Will this make a TextFile Connection to Sql Server 2000
2. Why is "." as first parameter ie Servername? any singnificance for "."
3. "Mypackage" is just a string or do we need to create a package and provide that name in the packagename parameter

Thanks a ton
s



----- Allan Mitchell wrote: ----

You need to add a ref to the DTS Package Object librar

Dim p As New DTS.Packag

Dim cn As DTS.Connectio

p.LoadFromSQLServer(".", ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
"MyPackage"

For Each cn In p.Connection

If cn.ProviderID = "DTSFlatFile" Then 'text Fil

'ideally you would know the name of the connectio

'What is the text qualifier propert

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value

'Now change i

cn.ConnectionProperties.Item("Text Qualifier").Value = "£

'Have a loo

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value



End I

Nex

p.UnInitialize(


--
--

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


"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in messag
news:5E8F2BD3-27DF-471D-9BC3-114C07C8FE02 (AT) microsoft (DOT) com..
Quote:
Hi
1. Can anyone tell me how to connect a Text File(source) as datasourc
through programming (not through wizard) in vb.net
2. Is the Text Qualifier property present in connectionproperties of a DT
connection? If so, is it read only or can we modify the property with an
text qualifier like single quote, double quotes etc
Quote:
Please provide names of necessary com objects to add reference in th
project and also syntax of the connection, task & connectionpropertie
FYI, I am using bulkInsertTask to import from a text file to a sql serve
2000 table. Is there still a better way to do this job
Thanks for your help
s


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

Default Re: DTS connection & BulkInsertTask - 05-04-2004 , 02:54 PM



Are you building a package from scratch?
If so why?

No my example does not create a text file connection it will highlight the
connections that are text files and you can then go on to manipulate them/it
.. is a shortcut name for the local server although I personally do not use
it I used it here to shield the name of my actual server
MyPackage is the name of the package I want to load up. It is a package
already built.



--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Allan, Can you explain:

p.LoadFromSQLServer(".", ,
,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTru stedConnection, , ,
,"MyPackage")
Quote:
1. Will this make a TextFile Connection to Sql Server 2000?
2. Why is "." as first parameter ie Servername? any singnificance for "."?
3. "Mypackage" is just a string or do we need to create a package and
provide that name in the packagename parameter?

Thanks a ton,
sp





----- Allan Mitchell wrote: -----

You need to add a ref to the DTS Package Object library

Dim p As New DTS.Package

Dim cn As DTS.Connection

p.LoadFromSQLServer(".", , ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
,
"MyPackage")

For Each cn In p.Connections

If cn.ProviderID = "DTSFlatFile" Then 'text File

'ideally you would know the name of the connection

'What is the text qualifier property

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value)

'Now change it

cn.ConnectionProperties.Item("Text Qualifier").Value = "£"

'Have a look

MessageBox.Show(cn.ConnectionProperties.Item("Text Qualifier").Value)



End If

Next

p.UnInitialize()


--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:5E8F2BD3-27DF-471D-9BC3-114C07C8FE02 (AT) microsoft (DOT) com...
Hi,
1. Can anyone tell me how to connect a Text File(source) as
datasource
through programming (not through wizard) in vb.net?
2. Is the Text Qualifier property present in connectionproperties
of a DTS
connection? If so, is it read only or can we modify the property
with any
text qualifier like single quote, double quotes etc?
Please provide names of necessary com objects to add reference in
the
project and also syntax of the connection, task &
connectionproperties
FYI, I am using bulkInsertTask to import from a text file to a sql
server
2000 table. Is there still a better way to do this job?
Thanks for your help,
sp




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

Default Re: DTS connection & BulkInsertTask - 05-04-2004 , 03:32 PM



This is a very quick example

Dim p As New DTS.Package

Dim tcn As DTS.Connection

p.Name = "My Dot Net Package"

tcn = p.Connections.[New]("DTSFlatFile")

tcn.DataSource = "C:\MyFile.txt"

With tcn.ConnectionProperties

..Item("Mode").Value = 3

..Item("Row Delimiter").Value = Microsoft.VisualBasic.ControlChars.CrLf

..Item("Text Qualifier").Value = """"

..Item("File Type").Value = 1

..Item("Column Delimiter").Value = ","

End With



tcn.Name = "Text File (Destination)"

tcn.Reusable = True

tcn.ConnectImmediate = False

tcn.ConnectionTimeout = 60

tcn.UseTrustedConnection = False

tcn.UseDSL = False

tcn.ID = 1

p.Connections.Add(tcn)



p.SaveToSQLServer(".", , ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , , )



You may want to try building a package in designer | saving as a VB file and
looking at what is generated.






--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"SP" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Allan,

Ya! I am building a package from scratch and not able to create a text
file connection. The other things you explained clarified some of my other
problems. Thanks for that. Will you please provide me with an example, how
to create a text file connection in vb.net? Any references to add for that?
Quote:
Thanks,
SP

----- Allan Mitchell wrote: -----

Are you building a package from scratch?
If so why?

No my example does not create a text file connection it will
highlight the
connections that are text files and you can then go on to manipulate
them/it
.. is a shortcut name for the local server although I personally do
not use
it I used it here to shield the name of my actual server
MyPackage is the name of the package I want to load up. It is a
package
already built.



--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:31475B5B-B7FC-4E71-B702-83EB08E55012 (AT) microsoft (DOT) com...
Allan, Can you explain:
p.LoadFromSQLServer(".", ,
,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTru stedConnection, , ,
,"MyPackage")
1. Will this make a TextFile Connection to Sql Server 2000?
2. Why is "." as first parameter ie Servername? any singnificance
for "."?
3. "Mypackage" is just a string or do we need to create a package
and
provide that name in the packagename parameter?
Thanks a ton,
sp
----- Allan Mitchell wrote: -----
You need to add a ref to the DTS Package Object library
Dim p As New DTS.Package
Dim cn As DTS.Connection
p.LoadFromSQLServer(".", , ,

DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
,
"MyPackage")
For Each cn In p.Connections
If cn.ProviderID = "DTSFlatFile" Then 'text File
'ideally you would know the name of the connection
'What is the text qualifier property
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
'Now change it
cn.ConnectionProperties.Item("Text Qualifier").Value = "£"
'Have a look
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
End If
Next
p.UnInitialize()
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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
"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:5E8F2BD3-27DF-471D-9BC3-114C07C8FE02 (AT) microsoft (DOT) com...
Hi,
1. Can anyone tell me how to connect a Text File(source) as
datasource
through programming (not through wizard) in vb.net?
2. Is the Text Qualifier property present in connectionproperties
of a DTS
connection? If so, is it read only or can we modify the
property
with any
text qualifier like single quote, double quotes etc?
Please provide names of necessary com objects to add reference in
the
project and also syntax of the connection, task &
connectionproperties
FYI, I am using bulkInsertTask to import from a text file to a
sql
server
2000 table. Is there still a better way to do this job?
Thanks for your help,
sp




Reply With Quote
  #6  
Old   
SP
 
Posts: n/a

Default Re: DTS connection & BulkInsertTask - 05-04-2004 , 04:16 PM



Thanks Allan, It worked for me without any errors. However, I have a question

I am not specifying destination sql server table name, so where will be the data inserted? Do I need to give the sql server table name in place of "Text File (Destination)" in tcn.Name = "Text File (Destination) property? If not, where to specify the table name

Thanks alot for your prompt and quick help
S




----- Allan Mitchell wrote: ----

This is a very quick exampl

Dim p As New DTS.Packag

Dim tcn As DTS.Connectio

p.Name = "My Dot Net Package

tcn = p.Connections.[New]("DTSFlatFile"

tcn.DataSource = "C:\MyFile.txt

With tcn.ConnectionPropertie

..Item("Mode").Value =

..Item("Row Delimiter").Value = Microsoft.VisualBasic.ControlChars.CrL

..Item("Text Qualifier").Value = """

..Item("File Type").Value =

..Item("Column Delimiter").Value = ",

End Wit



tcn.Name = "Text File (Destination)

tcn.Reusable = Tru

tcn.ConnectImmediate = Fals

tcn.ConnectionTimeout = 6

tcn.UseTrustedConnection = Fals

tcn.UseDSL = Fals

tcn.ID =

p.Connections.Add(tcn



p.SaveToSQLServer(".", ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , ,



You may want to try building a package in designer | saving as a VB file an
looking at what is generated






--
--

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


"SP" <anonymous (AT) discussions (DOT) microsoft.com> wrote in messag
news:76B3A9E9-7248-4BC2-80C8-AE7FA9C153E1 (AT) microsoft (DOT) com..
Quote:
Allan
Ya! I am building a package from scratch and not able to create a tex
file connection. The other things you explained clarified some of my othe
problems. Thanks for that. Will you please provide me with an example, ho
to create a text file connection in vb.net? Any references to add for that
Quote:
Thanks
S
----- Allan Mitchell wrote: ----
Are you building a package from scratch
If so why
No my example does not create a text file connection it wil
highlight th
connections that are text files and you can then go on to manipulat
them/i
.. is a shortcut name for the local server although I personally d
not us
it I used it here to shield the name of my actual serve
MyPackage is the name of the package I want to load up. It is
packag
already built
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP
www.SQLDTS.com - The site for all your DTS needs
I support PASS - the definitive, global communit
for SQL Server professionals - http://www.sqlpass.or
"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in messag
news:31475B5B-B7FC-4E71-B702-83EB08E55012 (AT) microsoft (DOT) com..
Allan, Can you explain
p.LoadFromSQLServer(".",
,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTru stedConnection, ,
,"MyPackage"
1. Will this make a TextFile Connection to Sql Server 2000
2. Why is "." as first parameter ie Servername? any singnificanc
for "."
3. "Mypackage" is just a string or do we need to create a packag
an
provide that name in the packagename parameter
Thanks a ton
s
----- Allan Mitchell wrote: ----
You need to add a ref to the DTS Package Object librar
Dim p As New DTS.Packag
Dim cn As DTS.Connectio
p.LoadFromSQLServer(".", , ,

DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
,
"MyPackage")
For Each cn In p.Connections
If cn.ProviderID = "DTSFlatFile" Then 'text File
'ideally you would know the name of the connection
'What is the text qualifier property
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
'Now change it
cn.ConnectionProperties.Item("Text Qualifier").Value = "£"
'Have a look
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
End If
Next
p.UnInitialize()
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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
"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:5E8F2BD3-27DF-471D-9BC3-114C07C8FE02 (AT) microsoft (DOT) com...
Hi,
1. Can anyone tell me how to connect a Text File(source) as
datasource
through programming (not through wizard) in vb.net?
2. Is the Text Qualifier property present in connectionproperties
of a DTS
connection? If so, is it read only or can we modify the
property
with any
text qualifier like single quote, double quotes etc?
Please provide names of necessary com objects to add reference in
the
project and also syntax of the connection, task &> connectionproperties
FYI, I am using bulkInsertTask to import from a text file to a
sql
server
2000 table. Is there still a better way to do this job?
Thanks for your help,
sp


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

Default Re: DTS connection & BulkInsertTask - 05-05-2004 , 02:48 AM



All my code does is create a text file.

To actually do something with the text file you would need to Add andother
connection, create a datapump task, n transformations objects etc etc.

As I said build the package in designer and then export to VB. This will
show you the things you need to cover in your creating a package.

--

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

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"SP" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Thanks Allan, It worked for me without any errors. However, I have a
question:

I am not specifying destination sql server table name, so where will be
the data inserted? Do I need to give the sql server table name in place of
"Text File (Destination)" in tcn.Name = "Text File (Destination) property?
If not, where to specify the table name?
Quote:
Thanks alot for your prompt and quick help,
SP






----- Allan Mitchell wrote: -----

This is a very quick example

Dim p As New DTS.Package

Dim tcn As DTS.Connection

p.Name = "My Dot Net Package"

tcn = p.Connections.[New]("DTSFlatFile")

tcn.DataSource = "C:\MyFile.txt"

With tcn.ConnectionProperties

..Item("Mode").Value = 3

..Item("Row Delimiter").Value =
Microsoft.VisualBasic.ControlChars.CrLf

..Item("Text Qualifier").Value = """"

..Item("File Type").Value = 1

..Item("Column Delimiter").Value = ","

End With



tcn.Name = "Text File (Destination)"

tcn.Reusable = True

tcn.ConnectImmediate = False

tcn.ConnectionTimeout = 60

tcn.UseTrustedConnection = False

tcn.UseDSL = False

tcn.ID = 1

p.Connections.Add(tcn)



p.SaveToSQLServer(".", , ,
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
, )



You may want to try building a package in designer | saving as a VB
file and
looking at what is generated.






--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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


"SP" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:76B3A9E9-7248-4BC2-80C8-AE7FA9C153E1 (AT) microsoft (DOT) com...
Allan,
Ya! I am building a package from scratch and not able to create a
text
file connection. The other things you explained clarified some of my
other
problems. Thanks for that. Will you please provide me with an
example, how
to create a text file connection in vb.net? Any references to add
for that?
Thanks,
SP
----- Allan Mitchell wrote: -----
Are you building a package from scratch?
If so why?
No my example does not create a text file connection it will
highlight the
connections that are text files and you can then go on to
manipulate
them/it
.. is a shortcut name for the local server although I
personally do
not use
it I used it here to shield the name of my actual server
MyPackage is the name of the package I want to load up. It is
a
package
already built.
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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
"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:31475B5B-B7FC-4E71-B702-83EB08E55012 (AT) microsoft (DOT) com...
Allan, Can you explain:
p.LoadFromSQLServer(".", ,

,DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTru stedConnection, , ,
,"MyPackage")
1. Will this make a TextFile Connection to Sql Server 2000?
2. Why is "." as first parameter ie Servername? any singnificance
for "."?
3. "Mypackage" is just a string or do we need to create a package
and
provide that name in the packagename parameter?
Thanks a ton,
sp
----- Allan Mitchell wrote: -----
You need to add a ref to the DTS Package Object library
Dim p As New DTS.Package
Dim cn As DTS.Connection
p.LoadFromSQLServer(".", , ,

DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , ,
,
"MyPackage")
For Each cn In p.Connections
If cn.ProviderID = "DTSFlatFile" Then 'text File
'ideally you would know the name of the connection
'What is the text qualifier property
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
'Now change it
cn.ConnectionProperties.Item("Text Qualifier").Value = "£"
'Have a look
MessageBox.Show(cn.ConnectionProperties.Item("Text
Qualifier").Value)
End If
Next
p.UnInitialize()
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
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
"sp" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message
news:5E8F2BD3-27DF-471D-9BC3-114C07C8FE02 (AT) microsoft (DOT) com...
Hi,
1. Can anyone tell me how to connect a Text File(source) as
datasource
through programming (not through wizard) in vb.net?
2. Is the Text Qualifier property present in connectionproperties
of a DTS
connection? If so, is it read only or can we modify the
property
with any
text qualifier like single quote, double quotes etc?
Please provide names of necessary com objects to add reference
in
the
project and also syntax of the connection, task &
connectionproperties
FYI, I am using bulkInsertTask to import from a text file to a
sql
server
2000 table. Is there still a better way to do this job?
Thanks for your help,
sp




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.