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 2005 Forums
 Transact-SQL (2005)
 problem with xp_cmdshell bcp

Author  Topic 

coder
Starting Member

16 Posts

Posted - 2007-05-30 : 12:48:51

Hi,

I've been trying to create an xls file named testing.xls on my C drive with this statement with SqlCommand.ExecuteNonQuery().

"Exec Master..xp_cmdshell 'bcp \"Select * from easdemo.dbo.customer\" queryout \"C:\\testing.xls\" -c'";

The command executes, I don't get any errors, but I don't see the file on my C drive...

I used the exact same code to run this statement without any problems:

"insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\\testing.xls;','SELECT * FROM [Sheet1$]') select * from EASDemo.dbo.customer";

But I'd rather not use this method if I have to create the xls file ahead of time.

Can somebody help? Thanks!

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-05-30 : 13:00:08
don't do that. if you are in code already, just use System.Diagnostics.Process to invoke bcp.exe.

EDIT: the reason you don't see a file is because you are writing the file to the server, not your client. why? because you are invoking with xp_cmdshell. if you use the Process class you won't have this problem, because then bcp will be invoked on the client.


www.elsasoft.org
Go to Top of Page
   

- Advertisement -