dbTalk Databases Forums  

Printing in DTS Activex script

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Printing in DTS Activex script in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
etcarine via SQLMonster.com
 
Posts: n/a

Default Printing in DTS Activex script - 07-19-2005 , 02:08 PM







I have a package that runs every day and prints out a series of reports. The
reports are generated into text files and printed by feeding the file name to
a Word application object and then using the PrintOut method to print the
file. I also select the printer. On occasion, say once or twice a month, I
get the following error:
Error Description: The remote server machine does not exist or is unavailable:

'appWord.Documents'
Error on Line 162:
<<Set objWord = appWord.Documents.Open(strFileName, False, True, , , , , , , ,

"Plain Text")>>
I can't tell what the message means, as the file (strFileName) and the dts
package are on the same computer. (the printer is on a remote computer).

How can I make it more reliable?

The VB source code of the print function is below:

'============================================
Function mcPrint(strFileName, strPrinterName)
'============================================
Const wdOrientLandscape = 1
Const wdDoNotSaveChanges = 0
Const wdLineSpaceExactly = 4
Const wdLineSpaceAtLeast = 3

Dim FileName
Dim aRange
Dim thatTime
Dim thisTime
Dim strCurrentPrinter
Const acPRDPVertical = 2

mcPrint = DTSTaskExecResult_Success
If strPrinterName = "" Then
WriteToLog strFileName & " NOT printed.", 0
Exit Function
End If

Set objWord = appWord.Documents.Open(strFileName, False, True, , , , , , ,
, "Plain Text")
Set aRange = appWord.ActiveDocument.Range
aRange.WholeStory
aRange.Font.Name = DTSGlobalVariables("Font").value
aRange.Font.Size = CInt(DTSGlobalVariables("Size").value)

appWord.ActiveDocument.Paragraphs.LineSpacingRule = wdLineSpaceExactly
appWord.ActiveDocument.Paragraphs.LineSpacing = CInt(DTSGlobalVariables
("Size").value)

appWord.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
appWord.ActiveDocument.PageSetup.TopMargin = CInt(DTSGlobalVariables
("TopMargin").value)
appWord.ActiveDocument.PageSetup.BottomMargin = CInt(DTSGlobalVariables
("BottomMargin").value)
appWord.ActiveDocument.PageSetup.LeftMargin = CInt(DTSGlobalVariables
("LeftMargin").value)
appWord.ActiveDocument.PageSetup.RightMargin = CInt(DTSGlobalVariables
("RightMargin").value)
appWord.Options.PrintBackground = False

iSpot = InStr(1, strCurrentPrinter, strPrinterName)

objWord.PrintOut
WriteToLog "Printed " & strFileName & " on " & strPrinterName, 0

mcPrint = DTSTaskExecResult_Success

End Function 'mcPrint

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-20-2005 , 03:07 PM






In message <5190F80E83C0D (AT) SQLMonster (DOT) com>, etcarine via SQLMonster.com
<forum (AT) SQLMonster (DOT) com> writes
Quote:
I have a package that runs every day and prints out a series of reports. The
reports are generated into text files and printed by feeding the file name to
a Word application object and then using the PrintOut method to print the
file. I also select the printer. On occasion, say once or twice a month, I
get the following error:
Error Description: The remote server machine does not exist or is unavailable:

'appWord.Documents'
Error on Line 162:
Set objWord = appWord.Documents.Open(strFileName, False, True, , , , , , , ,

"Plain Text")
I can't tell what the message means, as the file (strFileName) and the dts
package are on the same computer. (the printer is on a remote computer).

How can I make it more reliable?

Don't use Office automation, it is just not designed for unattended use
like this.

Have you tried searching the MS KB for the error message. There are a
couple of articles that mention it, nothing matching, but gives you a
feel.

I'd suggest that your lack of clean-up code could cause issues, with old
instances floating about. You really should be use the Close/Quit type
methods on all automation objects such as this. Also Set to Nothing when
done.

You may still see winword.exe processes floating about though. (Have you
looked?). I have used scheduled jobs with the kill command to ensure I
clean up fully after such jobs.



--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #3  
Old   
etcarine via SQLMonster.com
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-21-2005 , 08:00 AM




Darren,
Good thinking. The surrounding code that calls mcPrint looks like this:
<<
DTSGlobalVariables("InitialPrinter").value = appWord.ActivePrinter
ConnectToPrinter (DTSGlobalVariables("Printer").value)
appWord.ActivePrinter = DTSGlobalVariables("Printer").value
WriteToLog "Changed Active Printer from " & DTSGlobalVariables
("InitialPrinter").value & " to " & DTSGlobalVariables("Printer").value, 1

mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_1").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_2").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_3").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_4").value, DTSGlobalVariables("Printer").Value

appWord.ActivePrinter = DTSGlobalVariables("InitialPrinter").value
WriteToLog "Changed Active Printer back to " & DTSGlobalVariables
("InitialPrinter").value, 1
appWord.Quit wdDoNotSaveChanges
Set objWord = nothing
Set appWord = nothing
Set objNetwork = nothing
WriteToLog "Quit Winword.", 1
Quote:
So I do a fair amount of cleaning up. I'll check again to see if any Winword.
exe's are left around, but my guess is that it's ok. If I don't use VBA what
would I do? I need to send the reports to a printer, and the version of SQL
Server/Windows that the production system is running on doesn't even have a
printer object. In fact, if I allow the package to run under the System
session, it can't see the printers at all.
Regards,
Edwin


--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-21-2005 , 05:17 PM



In message <51A6E5A0FFA1A (AT) SQLMonster (DOT) com>, etcarine via SQLMonster.com
<forum (AT) SQLMonster (DOT) com> writes
Quote:
Darren,
Good thinking. The surrounding code that calls mcPrint looks like this:

DTSGlobalVariables("InitialPrinter").value = appWord.ActivePrinter
ConnectToPrinter (DTSGlobalVariables("Printer").value)
appWord.ActivePrinter = DTSGlobalVariables("Printer").value
WriteToLog "Changed Active Printer from " & DTSGlobalVariables
("InitialPrinter").value & " to " & DTSGlobalVariables("Printer").value, 1

mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_1").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_2").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_3").value, DTSGlobalVariables("Printer").Value
mcPrint DTSGlobalVariables("FilePath").Value & DTSGlobalVariables
("FileName_4").value, DTSGlobalVariables("Printer").Value

appWord.ActivePrinter = DTSGlobalVariables("InitialPrinter").value
WriteToLog "Changed Active Printer back to " & DTSGlobalVariables
("InitialPrinter").value, 1
appWord.Quit wdDoNotSaveChanges
Set objWord = nothing
Set appWord = nothing
Set objNetwork = nothing
WriteToLog "Quit Winword.", 1

So I do a fair amount of cleaning up. I'll check again to see if any Winword.
exe's are left around, but my guess is that it's ok. If I don't use VBA what
would I do? I need to send the reports to a printer, and the version of SQL
Server/Windows that the production system is running on doesn't even have a
printer object. In fact, if I allow the package to run under the System
session, it can't see the printers at all.
Regards,
Edwin


You probably don't have much choice, as the alternatives would be far
too much work, but the technology is not designed for the job, so it may
have issues from time to time. Watch for the exe's, as I've found that
to be an issue in the past. Rouge instances hang around and confuse
things later. As I mentioned, kill.exe can be used to fix that quite
well.


--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #5  
Old   
etcarine via SQLMonster.com
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-22-2005 , 01:29 PM




Darren,
There are no Winword.exe's laying around on the server, at this time.
Ofcourse it hasn't failed since June 30th. Where do I get Kill.exe? And then
I would add a line something like "execute Kill.exe Winword"? To make sure
there are none running when the dts package runs?
Regards,
Ed

Darren Green wrote:
Quote:
Darren,
Good thinking. The surrounding code that calls mcPrint looks like this:
[quoted text clipped - 31 lines]
Regards,
Edwin

You probably don't have much choice, as the alternatives would be far
too much work, but the technology is not designed for the job, so it may
have issues from time to time. Watch for the exe's, as I've found that
to be an issue in the past. Rouge instances hang around and confuse
things later. As I mentioned, kill.exe can be used to fix that quite
well.


--
Message posted via http://www.sqlmonster.com


Reply With Quote
  #6  
Old   
Darren Green
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-27-2005 , 02:02 PM



In message <51B658CCF45DE (AT) SQLMonster (DOT) com>, etcarine via SQLMonster.com
<forum (AT) SQLMonster (DOT) com> writes
Quote:
Darren,
There are no Winword.exe's laying around on the server, at this time.
Ofcourse it hasn't failed since June 30th. Where do I get Kill.exe?
Windows resource kit. Should be available to download on the MS site.

Quote:
And then
I would add a line something like "execute Kill.exe Winword"? To make sure
there are none running when the dts package runs?
Add a CmdExec step to the job or a Exec Proc Task to the start (and
maybe end) of the package.

kill winword.exe

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #7  
Old   
etcarine via SQLMonster.com
 
Posts: n/a

Default Re: Printing in DTS Activex script - 07-29-2005 , 10:00 AM




Darren,
It failed again yesterday. I checked for leftover winword.exe's and there
weren't any.
the log file reads:

Step Error Description:Error Code: 0
Error Source= Microsoft VBScript runtime error
Error Description: The remote server machine does not exist or is unavailable:
'appWord.Documents'

Error on Line 173
<<Line 173 is the open file line as previously posted>>
Step Error code: 800403FE
Step Error Help File:sqldts.hlp
Step Error Help Context ID:1100

Where can I find the error code and the context ID? This thing prints 28
files a week for 2 or 3 weeks in a row and then fails. There has to be a
reason for it.
Edwin

Darren Green wrote:
Quote:
Darren,
There are no Winword.exe's laying around on the server, at this time.
Ofcourse it hasn't failed since June 30th. Where do I get Kill.exe?

Windows resource kit. Should be available to download on the MS site.

And then
I would add a line something like "execute Kill.exe Winword"? To make sure
there are none running when the dts package runs?
Add a CmdExec step to the job or a Exec Proc Task to the start (and
maybe end) of the package.

kill winword.exe


--
Message posted via http://www.sqlmonster.com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.