Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BCP error "Unable to open BCP host data-file"

I've just create a new table in my sqlserver name exporttable now I'm trying to push out using cmd bcp but om getting this following error:

SQLState = S1000, NativeError = 0 Error = [Microsoft][ODBC Driver 13 for SQL Server]Unable to open BCP host data-file

Here is my path:

C:\Users\Serge>BCP Testing.bdo.Exporttable out "C:\Users\Serge\Desktop" -C -T

anyone can help ?

After trying Shnugos suggestion to add a filename I got this error:

SQLState = S0002, NativeError = 208 Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid object name 'Testing.bdo.ExportTable'. SQLState = 37000, NativeError = 11529 Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The metadata could not be determined because every code path results in an error; see previous errors for some of these. –

like image 998
MK55SDV Avatar asked Sep 13 '16 08:09

MK55SDV


3 Answers

From the error I take, that the data file cannot be opened:

C:\Users\Serge>BCP Testing.bdo.Exporttable out "C:\Users\Serge\Desktop\MyFile.txt" -C -T

I think, you have to add a filename behind the \Desktop. Desktop is an existing directory and cannot be opened as file ...

And - btw - it might be necessary to add -S Servername...

UPDATE

Found this here

Whenever I get this message, it's because of one of three things:

1) The path/filename is incorrect (check your typing / spelling)

2) The file does not exist. (make sure the file is where you expect it to be)

3) The file is already open by some other app. (close the other app to release the file)

For 1) and 2) - remember that paths are relative to where bcp is executing. Make sure that bcp.exe can access the file/path from it's context.

/Kenneth

like image 135
Shnugo Avatar answered Oct 19 '22 08:10

Shnugo


If you are running BCP through xp_cmdshell, run the following--> xp_cmdshell 'whoami'; GO --Make sure whatever user value you get back has full access to the file in question

like image 21
Josh McCoy Avatar answered Oct 19 '22 09:10

Josh McCoy


Run: EXEC master..xp_cmdshell 'DIR C:\Users\Serge\Desktop', this will show if you have access to the path.

Remember if you are accessing SQL remotely or over a network, the output ie. "C:\Users\Serge\Desktop" will be the C drive on the SQL Server, not your remote PC you are working on.

like image 5
user5818738 Avatar answered Oct 19 '22 08:10

user5818738