Question

When I use hidden path like \\\twn-a110093\s$\SNData1.csv, it does not work.

Error message:

[Microsoft][SQL Native Client] Unable to open BCP host data-file

Perhaps the '$' char is not recognized? How do I fix this problem?

Exec master..xp_cmdshell 'bcp " select * from sfm.dbo.tblSNDataDetail " queryout "\\twn-a110093\s$\SNData1.csv" -c -t, -T -S TWN-SQL-01'
Was it helpful?

Solution

Simply you can't BCP data directly to UNC path, there will be double hop issue, you have to set up constrained delegation between 2 servers. What you need to do is to first BCP to your local drive, then move/copy file to UNC path, which is actually faster than you directly BCP to UNC path even you set it up correctly. Believe it or not, try it.

OTHER TIPS

More likely a security issue:

"The Windows process spawned by xp_cmdshell has the same security rights as the SQL Server service account"

Be sure the SQL Server service account user has access to that path/file.

You are using an UNC path in BCP command, and actually you directly create a file on drive root S$. It will involve security check. What you can try is:

1. First change the path from drive root folder to a sub folder like \twn-a110093\s$\Test\SNData1.csv

2. Give SQL Server service account write permission to folder 'test', if SQL Server running under NT Service, then you need to give Network Service account write permission to folder

3.If "twn-a110093" is not the same server which SQl Server located, then on the file share folder, you probably need to give 'everyone' full permission.

4. If all doesn't work, then first BCP out to local folder, then robocopy file to UNC Path, like @Guna said, that is better to directly write file to UNC path, that is true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top