﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / create and print html file using SQL Server Agent job / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 09:52:03 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>I don't think there's anything unfortunate from my point of view, since you provided a solution even before I encoutered the problem! :-DSo, thank you in advance!!!</description><pubDate>Sun, 24 Feb 2013 12:16:49 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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.</description><pubDate>Sun, 24 Feb 2013 11:11:34 GMT</pubDate><dc:creator>MyDoggieJessie</dc:creator></item><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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) :-)</description><pubDate>Sun, 24 Feb 2013 11:10:22 GMT</pubDate><dc:creator>MyDoggieJessie</dc:creator></item><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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.</description><pubDate>Sun, 24 Feb 2013 11:00:40 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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 andb) 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? ;-)</description><pubDate>Sat, 23 Feb 2013 03:10:03 GMT</pubDate><dc:creator>LutzM</dc:creator></item><item><title>RE: create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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:[b]YOURDOMAIN\useraccount[/b] "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!</description><pubDate>Fri, 22 Feb 2013 18:12:44 GMT</pubDate><dc:creator>MyDoggieJessie</dc:creator></item><item><title>create and print html file using SQL Server Agent job</title><link>http://www.sqlservercentral.com/Forums/Topic1423300-391-1.aspx</link><description>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 ([url]http://www.printhtml.com/[/url]).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 [url]http://stackoverflow.com/questions/7189299/print-automatically-html-file-with-powershell[/url]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?TIALutz-- ================================================Here's some very basic sample code:[code="sql"]-- procedure to create a html file USE tempdbgo/*exec LutzM_printhtml 'some text'*/CREATE PROC dbo.LutzM_printhtml (@InVariable VARCHAR(10))asSELECT @InVariable FOR xml PATH('test')GO-- drop proc dbo.LutzM_printhtml[/code]-- ------------------------------------------------batch file (to be called using a cmdexec job step):bcp "EXEC tempdb.dbo.LutzM_printhtml 'some text'" queryout c:\temp\file.html -c -Tc:\temp\printhtml.exe file="c:\temp\file.html"REM c:\temp\file.html-- ------------------------------------------------</description><pubDate>Fri, 22 Feb 2013 17:05:27 GMT</pubDate><dc:creator>LutzM</dc:creator></item></channel></rss>