Home About Us SQL Interview Book Contact Us RSS
Articles
Tools
Code Snippets
Links
Tips & Tricks
FAQ
Resources
Articles
Code Snippets
Links
FAQ
Resources

Saravana Kumar
Vinod Kumar


Q: How can I list all available DTS Packages using VB .NET?

Answer:

There are many ways you can achieve this requirement. You can either use SQL-DMO to do the same. Or go for the conventional approach of using some queries on the database. In this example you will see that I would be using an in-built package to do the same.

' Copy from here ...
 
Dim strConn As String
 
'Build a strConnection string or any other valid formats you are comfortable
strConn = "Database=msdb;integrated Security=True;Server=<<Server Name>>"
 
'Create a strConnection object
Dim DTSConn As New System.Data.SqlClient.SqlstrConnection(strConn)
 
'Create a command object with query and strConnection as arguments
Dim DTSCmd As New System.Data.SqlClient.SqlCommand("EXEC sp_enum_dtspackages", DTSConn)
 
'open the command's strConnection object up
DTSCmd.strConnection.Open()
 
'Read all the data into a DataReader
Dim DTSReader As System.Data.SqlClient.SqlDataReader =DTSCmd.ExecuteReader(Data.CommandBehavior.Default)
 
'Loop through the collection of DTS Packages
While DTSReader.Read()
 'Display the record
 MsgBox(DTSReader.GetString(0))
End While
 
'Code Clear up activity
DTSReader.Close()
DTSConn.Close()
 
' Code copy ends here

So here we go ... Just copy paste the same in your windows forms and you should be up and running with the example.