February 24, 2016 at 8:19 am
Hi,
I have a database server say "server1", I am able to run the batch file to BCP out by doing RDP into the server1, but if I don't have an access to Server1 for doing a RDP into it, can I run the batch script from remote to BCP out the data? I have to do this only BCP utility.
Please let me know, how I could achieve this with out access to machine server1
February 24, 2016 at 8:25 am
use the server flag:
-S server_name\instance_name
Here's a complete example line with various flags:
BCP databasename.dbo.tablename out filename.DAT -c -S "servername\instancename" -T
I'm not necessarily sure the double quotes are needed but I use them anyways.
edit:
-c
"Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type, without prefixes and with \t (tab character) as the field separator and \r (newline character) as the row terminator. -c is not compatible with -w."
(lol stole that from https://msdn.microsoft.com/en-us/library/ms162802.aspx which has docs on the various flags)
-S obviously server name
-E lets you slam your values right over any pesky identity column specs, PAY CLOSE ATTENTION TO WHETHER YOU WANT TO USE THAT OR NOT!!!!!! (I removed that flag just in case you weren't paying attention anyways).
-T use trusted connection, ie., windows authentication.
February 24, 2016 at 8:49 am
Thanks for the reply, but In this code we are not specifying any file path, where does the .dat file falling into. any default location or do we need to give a specific path. I too want to know if we can give the UNC Path
February 24, 2016 at 8:56 am
if you don't specify a path (ie., just the file name), then its going to use the default directory that the process running bcp has at the time.
for instance, on the machine that you are running bcp on, if you do something like:
c:
cd \work
BCP databasename.dbo.tablename out filename.DAT -c -S "servername\instancename" -T
then the resulting file will be:
c:\work\filename.dat
Obviously I'm thinking that any legal fully specified file path would also work including unc paths, but the permissions for that path would need to be appropriate for the client process running bcp to write files to.
February 24, 2016 at 10:27 am
Its working, thanks
February 25, 2016 at 6:08 am
awesome glad it worked!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply