SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


create and print html file using SQL Server Agent job


create and print html file using SQL Server Agent job

Author
Message
LutzM
LutzM
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22703 Visits: 13559
Hi folks,

after almost a year "SSC abstinence" I'm back with a question:

Here's the scenario (2008R2):
The task is to call a stored procedure with some parameter, format the result set as a simple html file and send it to a printer. SSRS or SSIS are not an option, since this would be the only task where we'd use so it would be "oversized", at least at the moment. Sounds easy enough.

I got to the point where I have the html file created (using bcp in a batch file and a cmdexec job step).
To print the html file I tried to use a program called printhtml (http://www.printhtml.com/).
Since I couldn't get it to print from a SQL Server job, I created a simple batch file that calls bcp and after that the printhtml program (code see below).

When I run the batch from outside SQL Server, everything works fine and the html file will be printed.
But as soon as SQL Agent is involved, it will just hang forever at the printhtml program (the file will still be created) until I manually cancel the job.

I added a separate proxy to use my windows credentials instead of the SQL Agent account, but that didn't help either.

After a while I figured that the printhtml process will start (checked using task manager), but won't print. When killing this process, the SQL Agent job will finish immediately. Further "investigation" lead me to the assumption that this program does something like open the standard web explorer in a silent mode, print the file from there and close the app.

But the SQL Server Agent service seems to be unable to interact with another program that uses some sort of a GUI. To verify this assumption I changed the batch file and just opened the html file an an IE window instead of trying to print it. The job would still hang until I manually closed the IE tab.

My next approach was to try a PowerShell job step.
I tried the sample script based on http://stackoverflow.com/questions/7189299/print-automatically-html-file-with-powershell
But that didn't work either (disclaimer: my PowerShell experience is limited to the few lines of code I copied...).

Does anyone have an idea how to accomplish the task without using CLR, SSRS, SSIS? It would be a lot easier, if the application currently calling the sproc would be able to call a PS script, but that's not an option either. The print process needs to be started by the server, not the clients (the printer is installed at the server only).


Any ideas or hints? Am I hitting in the completely wrong direction?


TIA

Lutz



-- ================================================


Here's some very basic sample code:

-- procedure to create a html file 
USE tempdb
go

/*
exec LutzM_printhtml 'some text'
*/

CREATE PROC dbo.LutzM_printhtml
(
@InVariable VARCHAR(10)
)
as
SELECT @InVariable
FOR xml PATH('test')

GO
-- drop proc dbo.LutzM_printhtml





-- ------------------------------------------------
batch file (to be called using a cmdexec job step):

bcp "EXEC tempdb.dbo.LutzM_printhtml 'some text'" queryout c:\temp\file.html -c -T
c:\temp\printhtml.exe file="c:\temp\file.html"
REM c:\temp\file.html

-- ------------------------------------------------



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11836 Visits: 7444
The software needs to be registered using your proxy account that is used for the SQL Agent. You know how when you install some new software on the box, it works just fine for you, but when another user logs in, they get prompted with a model dialogue box when they go to use the software for the first time.

Although I'm not 100% positive on the syntax, from the command prompt try:
C:\runas /user:YOURDOMAIN\useraccount "C:\ProgramFiles\PrintHtml.exe"

This executes the application as that user and once the prompts and license information is entered (once) everything works as it should without any prompting.

Not sure this applies to your scenario but thought I'd share the experience - best of luck!

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
LutzM
LutzM
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22703 Visits: 13559
Thank you for your reply. I'll give it a try even though I don't think it will make a difference for two reasons:
a) the proxy I'm using is based on my Windows domain account, so it "should" be the same and
b) the program I'm calling doesn't need to be installed. It's a stand alone exe that just needs to be accessible (and that's the case, even when called by the SQL job)

But you'll never know until you've tried. Right? ;-)



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
LutzM
LutzM
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22703 Visits: 13559
After spending some more time searching for alternatives I found a software (http://www.coolutils.com/TotalHTMLConverterX) that doesn't need any GUI communication. Seems like it's the solution I've been looking for.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11836 Visits: 7444
Lutz, ironically enough, that's the exact same piece of software that we use (TotalHTMLConverter) and unfortunately, you will need to use the code I provided in order for it to work unattended - that's where I took the snippet of code from (or last implementation of the software on a new server) :-)

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
MyDoggieJessie
MyDoggieJessie
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11836 Visits: 7444
Note, it's only required for the very first time either you or the account that will be used runs it. If you ever change the proxy account you'll need to run it again.

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
LutzM
LutzM
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22703 Visits: 13559
I don't think there's anything unfortunate from my point of view, since you provided a solution even before I encoutered the problem! :-D

So, thank you in advance!!!



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search