Today I was very frustrated I create some code a long time where I could save a package into a table as a xml object and spend the whole freaking day looking for it. Finally I did and here it is for future reference. Once I update the code to c# I will post the new code but in the meantime here it is:
Private Sub SaveFailPackage(ByVal pkg As Microsoft.SqlServer.Dts.Runtime.Package)
Dim SQLCon As New SqlClient.SqlConnection
Dim pkid As Int32 = CType(Dts.Variables("User::int_ArchiveExportId").Value, Int32)
Dim SQL As String = "[dbo].[usp_SsisStorage_InsUpd]"
Dim Host As ConnectionManager = Dts.Connections("Host")
Dim ServerName As String = CStr(Host.Properties("ServerName").GetValue(Host))
Dim DatabaseName As String = CStr(Host.Properties("InitialCatalog").GetValue(Host))
Dim Connstr As String = "Server=" + ServerName + ";Database=" + DatabaseName + ";Trusted_Connection=True"
Dim myPkgDoc As XmlDocument = New XmlDocument()
pkg.SaveToXML(myPkgDoc, Nothing, Nothing)
SQLCon.ConnectionString = Connstr
SQLCon.Open()
Dim sqlCmd As New SqlClient.SqlCommand(SQL, SQLCon)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.AddWithValue("ArchiveExportId", pkid)
sqlCmd.Parameters.AddWithValue("pkg", myPkgDoc.OuterXml)
sqlCmd.ExecuteNonQuery()
SQLCon.Close()
SQLCon = Nothing
sqlCmd = Nothing
End Sub
No comments:
Post a Comment