print to PDF using xp_cmdshell - sql-server

We are trying to use TSQL on SQL 2012 and OS 2012 to print PDF file from a specific directory using variables based on a lookup that populates these variables. The command we have works on SQL 2005 and 2003 datacenter OS. During our upgrade this now does not want to work. I am fairly sure we are just dealing with a syntax issue that is OS related but SQL is not saying what is the issue.
Here is the base query --
EXEC master.sys.xp_cmdshell '"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe /t" \\jde9appb\d$\JDEdwards\E910\PrintQueue\R5509108_TV0001_4970_PDF.pdf \\VMPS08\INF2808P'
The above runs in the OS 2003 and SQL 2005 but when we try it in OS 2012 and SQL 2012 it just spins. We have turned of UAC and verified that the execute user has all the necessary rights to the command shell and command shell is enabled. This has to be done thru a TSQL script since this is part a stored proc that gets called by the custom application. Also the foixut reader is the default application to read PDF files. The switch you see above is the silient mode to print directly to a queue.
Help help. This has been a real tough one to figure out.
I have actually gotten it to say Failure to initialize the printer by messing with the Syntax, but this is as far as I have gone. I even loaded the printer I am going to to make sure the system is trying to use the proper driver.
For some reason the double backslash is not showing correctly. Here is the fixed query that I need some help with please.
EXEC master.sys.xp_cmdshell '"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe /t" \\jde9appb\d$\JDEdwards\E910\PrintQueue\R5509108_TV0001_4970_PDF.pdf \\VMPS08\INF2808P'

We faced the exact same issue. We found it was caused by the network printers, though created for the user, not being available to the background process. Creating the printers locally, thus bypassing the print server solved the issue.

Related

How do I get the path to the SQL script that is executed by Microsoft SQL Server 2016?

I am trying to install some application on Windows Server 2019. The application relies on a database, so I also have SQL Server 2016 (v 13.0.1601.5) on the server. But during installation, I get an error message, basically telling me some SQL script, say "abc.sql" has encountered a problem and cannot continue. When I open SQL Server's XEven Profiler, I surely see what the problem is; it fails to create a stored procedure because of some bug in the code, something like this:
CREATE PROCEDURE [dbo].[doSomethingNice] (**#problematicParameter** int, #nonProblematicParameter int)
AS
BEGIN
SET NOCOUNT ON;
update [dbo].[SomeTable]
set SomeField =**#ProblematicParameter**
where
SomeOtherField= #nonProblematicParameter
END
Of course, the problem is the casing.
XEvent Profiler kindly specifies which application runs the query, and in this case, it is Windows Installer.
client_app_name: Windows Installer - Unicode
I believe (more likely hope), if I can somehow get hold of the original script file, abc.sql, I can fix it and run it from SQL Server Management Studio. This would work since the installer program provides the option of using an existing database instead of creating a new one.
I scoured the Temp directory but could not find the said script. I know it must be somewhere on the disk. How can I find where it is? Does XEvent Profiler provide that data?

SSIS Project Failing When Running As SQL Server Agent Job

I have designed a SSIS project and deployed it to SQL server and also created the job to run on daily basis but its giving me this error when executing this as job (doesnt give any error within VS):
There is this CLSid in this error message but there is no application associated to it in
--> Component Services -> Computers -> My Computer -> DCOM Config
But this CLSid is registered inside registry editor
About this particular task on which this error is occurring: This is a script task which is modifying and deleting the un-wanted rows from the excel file in which I am trying to write SQL table data.
Script task code looks like this:
I have been working for hours now trying to fix this problem but no success. Kindly guide me how can I fix this issue. If any other information is required related to this project, please let me know....
Doing Excel automation in a SQL Server agent job is totally unsupported and probably won't work.
To have even a ghost of a chance of making this work you'll need to run a real desktop session on the server and automate Excel in that. Excel expects a real user to be logged in with a full profile. And Excel has failure conditions where it displays a popup window, which you'll need to be able to access via remote desktop.
You can read and write Excel files on a server with the OpenXML SDK, without actually having to run Excel. There's also a wrapper library called ClosedXML which you may find easier to use than using OpenXML directly.
tl;dr;
You need to install Office (Excel) on the server AND ensure that you install it in a manner that mirrors the SQL Agent's expected bit-edness. Default for Agent is going to be 64bit, default for Office is still 32 :(
Error guessing
You have a script task that uses the Office interop libraries to delete some rows (2 through 11?) out of a spreadsheet.
You have Office installed on your machine and therefore you have the libraries installed. Excel still has COM based "stuff" in it, thus the interop and errors shrieking about the CLSid, registry, etc but that's likely just secondary errors because there is no base "application is not installed" exception to be thrown.
If Office is installed, then ensure your agent execution model matches the version of Office. If 32 bit Excel is already installed, don't potentially break everyone else's stuff by uninstalling and reinstalling as 64 bit, just got the Advanced section of the SQL Agent Job Step and check the 32bit box.
Once all that's done, then if you're still getting errors but new ones, then the existing comments mentioning permissions may come into play - it depends on where the Excel document actually exists (on the computer where SQL agent can access vs on the computer where it cannot vs networked drive)
Good luck in not finding people on the sanctions lists.

Getting insufficient memory error while running 270 MB script on SQL Server 2012

I am using SQL Server 2012, I have a script to update the DB, that script is approx 270 MB in size and contains some about 22,00,000 lines.
Error :
Error message : System.OutOfMemoryException
Also,
I tried Transact-SQL command Query method but at particular line its giving error message.
Sqlcmd: Error: Syntax error at line 709918 in file 'database.sql'.
But there is not syntax error.
Please provide any solution on this.
That's already quite big for SQL Management Studio, especially if the script contains long lines and anything too complex.
Your best options are probably:
Use sqlcmd instead of SQL Management Studio
Break the script down into multiple files you can execute one after another
Don't forget that even just for the file, you need at least 550 MiB of memory, since Management Studio is a .NET application and uses Unicode. And then there's the GUI, and the syntax analysis, and parsing... And since the script isn't streamed by SMSS, unlike SqlCmd, you will likely have the whole file in memory at least twice, and you're already getting close to the limit of the 32-bit application, especially on an 32-bit OS...
No Need to do any manual splitting or any command line execution.
Just download this software - Big SQL Script File Runner
It will save your full day.

Sql Advantage Error : Open Client is not configured correctly

I am trying to run the Sql Advantage editor but getting below mentioned error.
Internal failure while initializing the SQL Advantage.
Please check that Open Client is configured correctly.
Please check the SET command output in the attached screenshot.Also, I can see two folders in my system for OCS-12_5 and OCS-15_0. This may be causing this problem. I also tried to run a bat file with these commands but getting same error:
Bat file commands:
set SYBASE= C:\Sybase\OCS-12_5
set SYBASE_OCS=OCS-12_5
C:\Sybase\OCS-12_5\sqladv-12_5\sqladv.exe
Please suggest.
SQL Advantage is no longer supported with ASE 15.x
But you can probably still run it if you set your environment to 12.5 (it works for me). Put all the environment settings in a .bat file, and then (in the .bat file) kick off sqladv.exe.

Can osql.exe run as a standalone?

I have a program that runs osql.exe from microsoft sql server tools directory and runs a script.
The problem is that on computers that don't have an installation of sql server, this tool is missing. So my question is whether or not is possible to run it as a standalone( along with any dll that may be required ) meaning that run them from Process.Start from a local directory of the application.
Yes, you can. Just copy the binary and off you go.
Why are you spawning osql?
I've written simple programs to execute scripts using SMO - mostly insired by this post.
EDIT
The jist of the post is to use SQL Server Management Objects (SMO). Server.ConnectionContext.ExecuteNonQuery parses SQL with GO statements in it.

Resources