Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 xp_cmdshell Problems

Author  Topic 

khillabolt
Starting Member

2 Posts

Posted - 2003-03-18 : 14:21:31
Greetings,

I am doing something similiar to this: [url]http://www.sqlteam.com/item.asp?ItemID=4722[/url]

Secondary on my list of things to figure out, is how to send this newly created text file to a printer (automatically). My first thought was to whip up a simple VB app. that would accept the file name (and path) and print it using the code below:

<snip>
Open Command$ For Input As #1 'Could be any file name
Do
Input #1, strTextFile
Printer.Print strTextFile
Loop

Close #1
On Error GoTo 0
Printer.EndDoc
Call ExitProcess(0)

</snip>

I couple caveats I've already uncovered. You must make a call to ExitProcess (from Public Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)) otherwise the xp_cmdshell never returns, and the process is left hanging.

Here's the problem: I can get the export working, and my VB app works from a command line, but not from xp_cmdshell. It always returns Error 482 - Printer Error.

IF @IsPrinter = 1
BEGIN
PRINT 'Print file'
SET @PrintCommand = 'FSControlPrint.exe '+@FileName
EXEC master..xp_cmdshell @PrintCommand
END


Anyone done something remotely close to this? I'm really stuck...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-18 : 14:30:35
Well since it works from the command line, the problem is most likely with the limitations of xp_cmdshell. Instead of using xp_cmdshell, why don't you just use WSH in your application instead? xp_cmdshell really shouldn't be used in applications because you have to give the user access to the stored procedure. If anyone ever figures out the password to the user, then they can pretty much do anything that they want on the server now, even if the account doesn't have the appropriate permissions on the server.

Tara
Go to Top of Page

khillabolt
Starting Member

2 Posts

Posted - 2003-03-18 : 14:37:49
The stored procedure is actually the application (my piece anyway). This little piece is part of a much larger application. Basically it's an automatic report printer. Instead of trying to build my own scheduling system, I was trying to use the sql jobs already built in MSDE. Time is money right?

I'm not too concerned with security, as the app (db et. al) is running on a localized MSDE database.

Any other ideas on how I could possibly send a text file to a printer (the setup default) from a stored procedure?

Thanks so much for your help.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-18 : 14:44:09
Instead of using a stored procedure, how about use DTS? From DTS, you could create an activex task that would do the WSH part. By doing it this way, you are still utilizing SQL Server.

If you are using SQL Server for this task just so that you can schedule it, then why don't you just use the Windows scheduler which is pretty much the same thing as the SQL Server scheduler?

Tara
Go to Top of Page
   

- Advertisement -