April 7, 2010 at 8:21 am
Hi All,
I am trying to create a Vb.NET Console application which loads SSIS package from SqlServer and tries to display details about the package Configuration and Connection details. Below is the piece of code I am trying.
pkg = app.LoadFromSqlServer("\\"+PackageName,server,uid,pwd,Nothing)
If (pkg.Configurations.Count > 0) Then
Console.WriteLine("Package Configuration Specified : Yes")
End If
dim Connections As Microsoft.SqlServer.Dts.Runtime.Connections
For Each strConnection As Microsoft.SqlServer.Dts.Runtime.ConnectionManager In Connections
Console.WriteLine("Connection Name: " & strConnection.Name)
Console.WriteLine("Connection String: " & strConnection.ConnectionString)
Next strConnection
How ever, when I run the above code, it throws the below error especially when running the For each statement.
"Object Reference NOt set to an instance of an object"
Can any one help me to understand what's wrong in the above code?
Thanks in advance.
Suresh
Regards,
Suresh Arumugam
April 7, 2010 at 9:22 am
Which statement does it die on? The ForEach, the Name, or the ConnectionString.
CEWII
April 7, 2010 at 9:30 am
It throws error when running "For each" line.
Thanks for your time..
Suresh
Regards,
Suresh Arumugam
April 7, 2010 at 9:37 am
It seems as if app.LoadFromSqlServer("\\"+PackageName,server,uid,pwd,Nothing) is returning no value so when you get to - If (pkg.Configurations.Count > 0) - Its returning the error. Try placing a watch on that line and check what is being returned
April 7, 2010 at 9:47 am
I have tested by commenting the whole For Each block and could see my code working. When I uncommented it and debugged, the error originated exactly at FOR EACH statement line.
Trying to understand the issue..
Suresh
Regards,
Suresh Arumugam
April 7, 2010 at 10:00 am
Did you realize that the connections variable will NEVER contain anything. You define it but never populate it. When you define it, it is not defined as new. What this means is that the foreach can't work. You might populate it immediately after the definition from the package object.
CEWII
April 7, 2010 at 10:14 am
Thanks Elliott for pointing out the issue.
I have updated the For each loop to directly refer pkg.Connections instead of declaring new Connections obect.
For Each strConnection As Microsoft.SqlServer.Dts.Runtime.ConnectionManager In pkg.Connections
Thanks all for your responses.
-Suresh
Regards,
Suresh Arumugam
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply