Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to backup sqlserver database using c# code.
For that i am using "BACKUP DATABASE" query.


So, suppose my "SQL server" is installed on same pc and i am trying to
running this query then this query is working perfectly.

But

suppose "SQL server" is installed on network environment means some on another system

I want to take "SQL server" database to my local system drive.

for example,

sql sever is installed on "TEST_SERVER"
and
another pc (say admin-pc) which is connected to same network
trying to take sqlserver database to local drive of "admin-pc"

what i am facing issue is that when i am trying to run code from local pc,
it is unable to access local system drive.



Getting error like this

Error


Means

it is able to connect sql server database.

it is able to take backup on system on which sql server is installed.

is is not able to take backup on local system drive

What I have tried:

BACKUP DATABASE test TO DISK = D:\1.bak
Posted
Updated 23-Mar-22 5:30am
v3

On remote location, create a share folder on your network environment and use the following query:
SQL
BACKUP DATABASE DatabaseName   
   TO DISK = 'YourSharedPath\DatabaseName.bak'

Your shared path could be like \\TEST_SERVER\SQLBackup\:
 
Share this answer
 
v3
You would have to create a folder on your admin machine and share it, giving the account that's running your SQL Server services access to the share and appropriate permissions.

But, you would normally never do this as your machine would have to be on the network and running in order for the backup job to work. It would be better if the back was written to a place that is up and running all the time and then you just copy that backup to your own machine when you need it. Keep in mind, you're going to have to make sure the data is kept secure per company policy.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900