Search code examples
c#sqldatabase-backupsdatabase-restoreremote-backup

backup and restore db sql from C#


Good, I work on my application to perform backups and restore of an sql database. In local mode I have no problems. Using "SqlDataSourceEnumerator" I get list of lan servers. Start my application correctly, ready the available servers, I connect correctly. The problem that I have when I want to create the path of my Savefile.dialog to locate the backups creates the backup in the machine of the SQL server and not in the machine from which I connect. My question is: how could I solve the route?

 S = save1.FileName;

Query ("Backup database" + cmbBase.Text + "to disk = '" + s + "' WITH INIT");
(Maybe in the route I should add the ip)

thanks for your help.


Solution

  • The BACKUP command in TSQL will not allow a network path to be referenced in the SQL command. So if you backup to (for example) C:\Temp\FRED.BAK, it will always be a path that is local to the machine upon which the SQL Server instance is running.

    So to do what I suspect you want to do, you would need to - (a) backup to some folder on the machine running the SQL Server instance and then (b) copy the file from there to a central repository.

    I would also add that the RESTORE command in TSQL also does not allow references to network paths, the file being restored also needs to be on a drive local to the machine running the SQL Server instance.