Sql-server – Restore database to a instance in network

backuprestoresql serversql-server-2008-r2

We are creating a application which requires sql database as backend to store data. So when user install my application he chooses a sql instance and its details. There we plan to restore the database which is required for storing the users data etc.

So now if the user selects a sql instance of a another pc in the network then, how i should restore the database? Giving network path in backup database t-sql command is not a good idea. So in this cases how the database is restored to a network path? What is the best practice for this.

Best Answer

So are there multiple backups that may be selected? I'm having a hard time following that portion of the question.

If there are a large number of backups that you don't want to port with the application installation, then you would be storing them on a network share accessible by all client machines that would be installing your application. If there was only one backup, and it was reasonably sized, or multiple backups that are reasonably sized, why wouldn't you just have those ship with the installation?

Provided that's not an option, what you could do is create logic to first copy the backup file from the share to a local directory. Think of it like this:

  1. Copy backup file from "\yourShareName\Dir1\backup_file.bak" to "C:\Some\Local\Dir\backup_file.bak"
  2. Restore your database from the local copy of the backup file