How to use DTS package in C#

J

juventusaurabh

Hi all,
I'm a rookie and would like to know how do I use the DTS
package in my C# code.
I actually want to input a pipe-delimited text file and convert it into
SQL tables and also validate the values in the data field (eg. the
state data field should not have more than 2 chars. .. etc).

Please help!

thanx
 
M

Michael Nemtsev

Hello juventusaurabh,

What's the DTS ?

j> I'm a rookie and would like to know how do I use the DTS
j> package in my C# code.
j> I actually want to input a pipe-delimited text file and convert it
j> into SQL tables and also validate the values in the data field (eg.
j> the state data field should not have more than 2 chars. .. etc).


---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

juventusaurabh said:
Hi all,
I'm a rookie and would like to know how do I use the DTS
package in my C# code.
I actually want to input a pipe-delimited text file and convert it into
SQL tables and also validate the values in the data field (eg. the
state data field should not have more than 2 chars. .. etc).

This is what I do, I create the DTS in the enterprise manager, when I'm sure
it does work as expected ( data convertion, etc) I save it in disk, this
create a DTS file, later on I use the code below to set the correct data
connections .
You can set a number of other parameters, take a look at the doc, the code
below will give you an idea of how to start


void RunPackage( string packSource, string packName, string dataSource)
{
try
{
Package2Class package = new Package2Class();
object pVarPersistStgOfHost = null;

// if you need to load from file
package.LoadFromStorageFile(
packSource,
null,
null,
null,
packName,
ref pVarPersistStgOfHost);

package._Package_Connections.Item(1).DataSource = dataSource;
package.Execute();
package.UnInitialize();

// force Release() on COM object
//
System.Runtime.InteropServices.Marshal.ReleaseComObject(package);
package = null;
}
catch(System.Runtime.InteropServices.COMException e)
{
Console.WriteLine("COMException {0}", e.ErrorCode.ToString() );
Console.WriteLine("{0}", e.Message);
Console.WriteLine("{0}", e.Source);
Console.WriteLine("Stack dump\n{0}\n", e.StackTrace);
Console.ReadLine();
}
catch(System.Exception e)
{
Console.WriteLine("Exception");
Console.WriteLine("{0}", e.Message);
Console.WriteLine("{0}", e.Source);
Console.WriteLine("Stack dump\n{0}\n", e.StackTrace);

Console.ReadLine();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top