siddhu
siddhu

Reputation: 31

What is wrong with my SQL command?

I am trying to put the query result into a PowerPoint file like the below

EXEC XP_CMDSHELL 'SQLCMD -Q "Select * From test_tbl" -O "E:test_tbl.ppt"'

but it is not working.

Below is the summary that I am getting

**output**

Sqlcmd: Warning: '-O' is an obsolete option and is ignored.
Msg 208, Level 16, State 1, Server SUMERU-49484E24, Line 1
Invalid object name 'TableName'.
NULL

Before executing this query I have already enabled the xp_cmdshell by using sp_configure.

Also I have the .ppt file in the proper location.

I have doing this just for my own sake of experiment.

Kindly help me in executing the same.

Using SQL Server 2005.

Edit:

I have changed the query like the below

EXEC XP_CMDSHELL 'SQLCMD -Q "Select * From test_tbl" -s "SUMERU-49484E24\SQLEXPRESS2008" -d "test" -E -o "D:t2.ppt"'

But the below is the error in the pptfile

HResult 0xFDC, Level 11, State 1
Cannot open database requested in login 'test'. Login fails.
HResult 0x4818, Level 14, State 1
Login failed for user 'NT AUTHORITY\SYSTEM'.
HResult 0x4, Level 16, State 1
Shared Memory Provider: I/O Error detected in read/write operation [4]. 
Sqlcmd: Error: Microsoft SQL Native Client : Communication link failure.

Thanks

Upvotes: 3

Views: 3042

Answers (1)

marc_s
marc_s

Reputation: 754618

I see a few problems:

  • the parameter for sqlcmd to define the output file is -o (lowercase) - not the -O (uppercase) you're using

  • you're not defining what server and database to connect to - you need to add -S (servername) and -d (database name) to your SQLCMD command line

  • you're not defining how to connect security-wise - either supply -E for a trusted connection (integrated Windows security) or define user and password using -U (login) and -P (password)

Upvotes: 2

Related Questions