Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Return error messages from xp_cmdshell without using temp tables

Posted on 2007-11-15
6
Medium Priority
?
246 Views
Last Modified: 2008-02-01
Hi Guys n Gals,

I've been asked to develop an SP that can run dos commands and isqlw. The SP has to return any error messages from the operating system or SQL Server. But I can't create temporary tables in the SP to store the error messages.  The bare bones SP looks like this so far ... any ideas?

Cheers,

Pete

-- This SP is for running xp_cmdshell and reporting back and operating system error messages
CREATE proc sp_RunCmd
 @MyCmd varchar (50), @Result varchar(250) OUTPUT
AS
-- @MyCmd - This will be a DOS cmd or isqlw statement e.g. @MyCmd = 'mkdir MyDir ' Or what ever

-- Normally I'd do  this but we can't create temp tables
CREATE TABLE #TempTable(Message VARCHAR(250))       -- can't do this
INSERT #TempTable                               
EXEC master.dbo.xp_cmdshell @MyCmd      
            
SELECT @Result = Message FROM #TempTable            
                        


0
Comment
Question by:Pete_Burke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20287836
>CREATE TABLE #TempTable(Message VARCHAR(250))       -- can't do this
why not?

0
 

Author Comment

by:Pete_Burke
ID: 20287860
Its a replica database and read only
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20287879
then you need to choose some alternative:
* put your procedure into another database
* try to create table table in another database explicitely
  CREATE TABLE tempdb..#TempTable(Message VARCHAR(250))    

0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20287885
Hello Pete_Burke,

you can create temp tables as physically they are created in the tempdb. and there is no other way other than using temp tables / table variables

now the wn is , if this is a read only db, how can u create an sp there

Aneesh R.
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20287898
Any Why you dont want to create #Temp tables? There is no other way round to deal with this is to redirect the output to a file and read that file from SP.
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20287907
Sorry a statement error in my comments.
Any Why you dont want to create #Temp tables? There is no other way round to deal with this except that you redirect the output to a file and read that file from SP and parse the text.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question