Home All Groups Group Topic Archive Search About

How do I run a DTS package from vb.net

Author
11 Sep 2006 9:56 PM
Gordon
Hi;

I am trying to execute a DTS package from within a vb.net module using
VS 2003.

I understand that you must add a reference to a com library.

I tried using a reference to Microsoft.DTSPackage.Object Library

Then doing "

Dim oPackage As Object = CreateObject("DTS.PAckage2")

I must have the wrong library selected because I am unable to enter

my next step oPackage.LoadFromSQlServer.

Where am I going wrong ?

Thanks,
--
Gordon

Author
11 Sep 2006 10:49 PM
Arnie Rowland
If you are only concerned with executing the DTS package, you have a couple
of options.

1. With the DTS Designer, save the package as a VBScript package.
Incorporate the VBScript into your VB Code.

2. Using the executable 'DTSRun.exe', run the package.

Look up DTSRun in Books Online.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


Show quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:429F60EC-79AE-42F3-9AD0-09B408ABF1A7@microsoft.com...
> Hi;
>
> I am trying to execute a DTS package from within a vb.net module using
> VS 2003.
>
> I understand that you must add a reference to a com library.
>
> I tried using a reference to Microsoft.DTSPackage.Object Library
>
> Then doing "
>
> Dim oPackage As Object = CreateObject("DTS.PAckage2")
>
> I must have the wrong library selected because I am unable to enter
>
> my next step oPackage.LoadFromSQlServer.
>
> Where am I going wrong ?
>
> Thanks,
> --
> Gordon
Author
12 Sep 2006 12:40 PM
Dan Guzman
> Dim oPackage As Object = CreateObject("DTS.PAckage2")

Why are you declaring the package as Object instead of DTS.Package2?  It's
best to use strong typing when applicable.

Check out http://www.sqldev.net/dts/ExecutePackage.htm for examples of
executing a DTS package directly from your VB.Net code.

--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:429F60EC-79AE-42F3-9AD0-09B408ABF1A7@microsoft.com...
> Hi;
>
> I am trying to execute a DTS package from within a vb.net module using
> VS 2003.
>
> I understand that you must add a reference to a com library.
>
> I tried using a reference to Microsoft.DTSPackage.Object Library
>
> Then doing "
>
> Dim oPackage As Object = CreateObject("DTS.PAckage2")
>
> I must have the wrong library selected because I am unable to enter
>
> my next step oPackage.LoadFromSQlServer.
>
> Where am I going wrong ?
>
> Thanks,
> --
> Gordon
Author
12 Sep 2006 9:06 PM
Gordon
Hi ;

Thanks for site info.


Now when I try to connect to DTS to execute a pkg like so:

   opkg.LoadFromSQLServer("BNG0193265y661y\TRSQL", , ,   
DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UsedTrustedConnection
         , , , ,"transUser_import")

I get the following error:

[DBNETLIB]{COnnectionOpen(Invalid Instance()).]Invalid Connection.

I have verified the server name and the fact that I can use trusted
connection.

I also have a reference set to DTS.

Supposedly all this is all  needed in your code is the above plus the
execute method.

Any insights would be greatly appreciated !,

--
Gordon


Show quote
"Dan Guzman" wrote:

> > Dim oPackage As Object = CreateObject("DTS.PAckage2")
>
> Why are you declaring the package as Object instead of DTS.Package2?  It's
> best to use strong typing when applicable.
>
> Check out http://www.sqldev.net/dts/ExecutePackage.htm for examples of
> executing a DTS package directly from your VB.Net code.
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
>
> "Gordon" <Gor***@discussions.microsoft.com> wrote in message
> news:429F60EC-79AE-42F3-9AD0-09B408ABF1A7@microsoft.com...
> > Hi;
> >
> > I am trying to execute a DTS package from within a vb.net module using
> > VS 2003.
> >
> > I understand that you must add a reference to a com library.
> >
> > I tried using a reference to Microsoft.DTSPackage.Object Library
> >
> > Then doing "
> >
> > Dim oPackage As Object = CreateObject("DTS.PAckage2")
> >
> > I must have the wrong library selected because I am unable to enter
> >
> > my next step oPackage.LoadFromSQlServer.
> >
> > Where am I going wrong ?
> >
> > Thanks,
> > --
> > Gordon
>
>
>
Author
13 Sep 2006 12:42 PM
Dan Guzman
> I have verified the server name and the fact that I can use trusted
> connection.

Did you test the connectivity from you application code or separately?  I
don't know the details of your environment but a different security context
may be the issue.

> Supposedly all this is all  needed in your code is the above plus the
> execute method.

Yes, that is correct.  Below is the snippet I successfully ran on my system
to test connectivity and execute a package.

    'test connectivity
    Dim testConnection As New SqlConnection( _
        "Data Source=MyServer\MyInstance;Integrated Security=SSPI")
    testConnection.Open()
    testConnection.Close()

    'execute package
    Dim testPackage As New DTS.Package2
    testPackage.LoadFromSQLServer("MyServer\MyInstance", , , _
        DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, , ,
, _
        "MyDtsPackage")
    testPackage.Execute()


--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:FC1ED9EC-1F02-40C6-84C8-95B39E000C69@microsoft.com...
> Hi ;
>
> Thanks for site info.
>
>
> Now when I try to connect to DTS to execute a pkg like so:
>
>   opkg.LoadFromSQLServer("BNG0193265y661y\TRSQL", , ,
> DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UsedTrustedConnection
>         , , , ,"transUser_import")
>
> I get the following error:
>
> [DBNETLIB]{COnnectionOpen(Invalid Instance()).]Invalid Connection.
>
> I have verified the server name and the fact that I can use trusted
> connection.
>
> I also have a reference set to DTS.
>
> Supposedly all this is all  needed in your code is the above plus the
> execute method.
>
> Any insights would be greatly appreciated !,
>
> --
> Gordon
>
>
> "Dan Guzman" wrote:
>
>> > Dim oPackage As Object = CreateObject("DTS.PAckage2")
>>
>> Why are you declaring the package as Object instead of DTS.Package2?
>> It's
>> best to use strong typing when applicable.
>>
>> Check out http://www.sqldev.net/dts/ExecutePackage.htm for examples of
>> executing a DTS package directly from your VB.Net code.
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Gordon" <Gor***@discussions.microsoft.com> wrote in message
>> news:429F60EC-79AE-42F3-9AD0-09B408ABF1A7@microsoft.com...
>> > Hi;
>> >
>> > I am trying to execute a DTS package from within a vb.net module using
>> > VS 2003.
>> >
>> > I understand that you must add a reference to a com library.
>> >
>> > I tried using a reference to Microsoft.DTSPackage.Object Library
>> >
>> > Then doing "
>> >
>> > Dim oPackage As Object = CreateObject("DTS.PAckage2")
>> >
>> > I must have the wrong library selected because I am unable to enter
>> >
>> > my next step oPackage.LoadFromSQlServer.
>> >
>> > Where am I going wrong ?
>> >
>> > Thanks,
>> > --
>> > Gordon
>>
>>
>>

AddThis Social Bookmark Button