0

I am trying to bulk export data from several tables to separate CSV files. I created a small .bat file to do the lift, but it keeps failing.

Here is the code:

bcp DB_name.Table_Name out C:\path_to_local_folder\table1.csv -S server_name\DB_Name -T

I don't know what I'm missing here, because this seems so simple, but I just can't get this to spit out any data. I'm guessing it doesn't work because the database is on a remote server, and I'm trying to dump the data to my local drive. Maybe that's the issue. Not sure.

I also tried the script from the link below, and that didn't do anything either.

SQL Server Management Studio 2012 - Export all tables of database as csv

Any thoughts, anyone?

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
ASH
  • 15,523
  • 6
  • 50
  • 116
  • 2
    *"it keeps failing"*? Can you elaborate? You have enough reputation to know you should be providing relevant error messages, or describing the unexpected behaviour. :) – Larnu Apr 23 '18 at 15:00
  • Yes, yes, I finally identified the error: Network-related or instance-specific error occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correctvand if SQL Server is configured to allow remote connections. – ASH Apr 23 '18 at 15:05
  • 1
    Please [edit](https://stackoverflow.com/posts/49984001/edit) your post with that information. Can you see any failed error messages in the SQL Server's logs? If not, then it sounds like the connection isn't reaching the SQL server; possibly a firewall issue or you've declared your connection details incorrectly. If yes, then please post those as well. – Larnu Apr 23 '18 at 15:08
  • 1
    have you googled your error message and tried anything? first hit is this article, and there are many others. See if they help. https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Jeremy Apr 23 '18 at 15:15
  • Yes, as always, I Googled for a solution before posting here. I've very difficult to do anything in my current environment. Everything that should work normally is disabled or locked down, so it's almost impossible to 'see' what is going on here. I'll look at the link. Thanks. – ASH Apr 23 '18 at 15:21
  • Did you try replacing C:\... with the full server name and path?? – Daniel Marcus Apr 23 '18 at 15:23
  • Well, the C: is the destination, right. It's supposed to go from the remote server to my hard drive. This actually worked just fine one month ago. I have no idea what changed in the past 30 days. I don't know of anything that changed on my end. – ASH Apr 23 '18 at 15:44

0 Answers0