0

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?

4

1 に答える 1

1

You don't specify a Server in your command. Add the -S option with the right value. If your server is the "Default" instance on your server you could put -S.

The steps to take to fix the database open error is explained by Pinal Dave

  1. If possible add more hard drive space either by removing of unnecessary files from hard drive or add new hard drive with larger size.

  2. Check if the database is set to Autogrow on.

  3. Check if the account which is trying to access the database has enough permission to perform operation.

  4. Make sure that .mdf and .ldf file are not marked as read only on operating system file system level.

于 2012-06-08T12:05:40.337 に答える