?
Solved

Return error messages from xp_cmdshell without using temp tables

Posted on 2007-11-15
6
Medium Priority
?
245 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

762 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