I am trying to export to a CSV file using BCP like this:
DECLARE @SQL AS VARCHAR(1000)
DECLARE @CMD AS VARCHAR(8000)
SET @SQL='SELECT * from Pondor.dbo.tblLD'
SET @CMD = 'bcp "' + @SQL + '" QUERYOUT "' + @FILE + '" -c -t "," -U"UserA" -P"Password"
exec master..xp_cmdshell @cmd
This does not work and throws the following error:
SQLState = 37000, NativeError = 945
Database 'Pondor' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
Doing a SELECT * from Pondor.dbo.tblLD
works and returns rows. Any ideas on what is wrong with the BCP command?