Hi all
I am attempting to create an SSIS package that uses data from SQL Server to automatically create letters. It all works fine except for when I try to change the active printer (oWord.ActivePrinter = Default_printer). At this point I get an error. I have used the same code in a VB.net application outside of SSIS and it works fine. Does anybody know what is wrong?
Error:
[Script Component [186]] Error: System.Runtime.InteropServices.COMException (0x800A1460): There is a printer error. at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper90 wrapper, Int32 inputID, IDTSBuffer90 pDTSBuffer, IntPtr bufferWirePacket)
[Code/]
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
'Start Word and open the document template.
oWord = New Word.Application
oWord.Visible = True
oDoc = oWord.Documents.Add("T:\PPM_Template.dot")
oDoc.Bookmarks.Item("Name").Range.Text = Row.Name.ToString
oDoc.Bookmarks.Item("Address1").Range.Text = Row.Address1.ToString
oDoc.Bookmarks.Item("Address2").Range.Text = Row.Address2.ToString
oDoc.Bookmarks.Item("Address3").Range.Text = Row.Address3.ToString
oDoc.Bookmarks.Item("Address4").Range.Text = Row.Address4.ToString
oDoc.Bookmarks.Item("Postcode").Range.Text = Row.Postcode.ToString
oDoc.Bookmarks.Item("Date").Range.Text = "Date: " & Today()
Dim r As Integer, rx As Integer
rx = 2 ' get count of the number of equipment items + 1 row for headers
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("Product").Range, 1, 3)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Borders.OutsideColor = Word.WdColor.wdColorBlack
oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Borders.InsideColor = Word.WdColor.wdColorBlack
oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Cell(1, 1).SetWidth(ColumnWidth:=250, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 2).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 3).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Range.Tables(1).Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter
oTable.Cell(1, 1).Range.Text = "Product"
oTable.Cell(1, 2).Range.Text = "Serial Number"
oTable.Cell(1, 3).Range.Text = "Fixed Price"
For r = 2 To rx
oTable.Rows.Add()
oTable.Cell(r, 1).Range.Text = Row.Product.ToString
oTable.Cell(r, 1).Range.Font.Bold = 0
oTable.Cell(r, 2).Range.Text = Row.SerialNR.ToString
oTable.Cell(r, 2).Range.Font.Bold = 0
oTable.Cell(r, 3).Range.Text = Row.Price.ToString
oTable.Cell(r, 3).Range.Font.Bold = 0
Next
Dim Default_printer As String = "UKCA_Courtney_Service_Copier250MF_Black"
oWord.ActivePrinter = Default_printer
Try
oDoc.PrintOut(True, True)
Catch exc As Exception
Console.WriteLine(exc.Message)
End Try
[/code]
Many Thanks in advance for any replies.
Tim
I am attempting to create an SSIS package that uses data from SQL Server to automatically create letters. It all works fine except for when I try to change the active printer (oWord.ActivePrinter = Default_printer). At this point I get an error. I have used the same code in a VB.net application outside of SSIS and it works fine. Does anybody know what is wrong?
Error:
[Script Component [186]] Error: System.Runtime.InteropServices.COMException (0x800A1460): There is a printer error. at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper90 wrapper, Int32 inputID, IDTSBuffer90 pDTSBuffer, IntPtr bufferWirePacket)
[Code/]
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
'Start Word and open the document template.
oWord = New Word.Application
oWord.Visible = True
oDoc = oWord.Documents.Add("T:\PPM_Template.dot")
oDoc.Bookmarks.Item("Name").Range.Text = Row.Name.ToString
oDoc.Bookmarks.Item("Address1").Range.Text = Row.Address1.ToString
oDoc.Bookmarks.Item("Address2").Range.Text = Row.Address2.ToString
oDoc.Bookmarks.Item("Address3").Range.Text = Row.Address3.ToString
oDoc.Bookmarks.Item("Address4").Range.Text = Row.Address4.ToString
oDoc.Bookmarks.Item("Postcode").Range.Text = Row.Postcode.ToString
oDoc.Bookmarks.Item("Date").Range.Text = "Date: " & Today()
Dim r As Integer, rx As Integer
rx = 2 ' get count of the number of equipment items + 1 row for headers
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("Product").Range, 1, 3)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Borders.OutsideColor = Word.WdColor.wdColorBlack
oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Borders.InsideColor = Word.WdColor.wdColorBlack
oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Cell(1, 1).SetWidth(ColumnWidth:=250, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 2).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 3).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Range.Tables(1).Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter
oTable.Cell(1, 1).Range.Text = "Product"
oTable.Cell(1, 2).Range.Text = "Serial Number"
oTable.Cell(1, 3).Range.Text = "Fixed Price"
For r = 2 To rx
oTable.Rows.Add()
oTable.Cell(r, 1).Range.Text = Row.Product.ToString
oTable.Cell(r, 1).Range.Font.Bold = 0
oTable.Cell(r, 2).Range.Text = Row.SerialNR.ToString
oTable.Cell(r, 2).Range.Font.Bold = 0
oTable.Cell(r, 3).Range.Text = Row.Price.ToString
oTable.Cell(r, 3).Range.Font.Bold = 0
Next
Dim Default_printer As String = "UKCA_Courtney_Service_Copier250MF_Black"
oWord.ActivePrinter = Default_printer
Try
oDoc.PrintOut(True, True)
Catch exc As Exception
Console.WriteLine(exc.Message)
End Try
[/code]
Many Thanks in advance for any replies.
Tim