I. How to establish a connection Server
Exec sp_addmediaserver 'srv _ lnk ', '', 'sqlodb', 'remote server name or IP address'
Exec sp_add1_srvlogin 'srv _ lnk ', 'false', null, 'username', 'Password'
Go
2. Use commands and local bak files to restore the remote database. steps:
1. Create a shared folder and set the folder where the bak files are stored as a shared folder.
Net share folder = D: \ tmp \ db. bak this command can be called through C #
If you want to cancel sharing, you can write
Net share folder Folder/delete
2. Enable xp_mongoshell. SQL server 2005/2008 disables this stored procedure by default.
-- Enable
Sp_configure 'show advanced options', 1
Reconfigure
Go
Sp_configure 'xp _ Your shell', 1
Reconfigure
Go
-- If you want to disable it, you can write it like this.
Sp_configure 'xp _ Your shell', 0
Reconfigure
Sp_configure 'show advanced options', 0
Reconfigure
3. Create a shared credit relationship. userName and pwd are the userName and password used to log on to the machine 192.224.109.64.
EXEC xp_cmdshell 'net use \ 192.224.109.64 \ login folder pwd/user: username ';
GO
EXEC xp_mongoshell 'net use \ 192.224.109.64 \ mongofolder/del ';
GO
The second sentence is how to cancel the shared credit relationship.
4. Run the recovery command.
Restore database
Restore database [dbName] from disk = n' \ 192.224.109.64 \ mongofolder \ db. bak 'with file = 1, move N 'dbnew' to N 'C: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA \ db. mdf ', move n' dbnew _ log' to n' C: \ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA \ dblog. ldf', NOUNLOAD, REPLACE, STATS = 10
Dbnew and dbnew_log are the Database Name and log file name during Backup.
The following statement
Select REVERSE (SUBSTRING (reverse (filename), charindex ('\', reverse (filename), 8000), name from sysfiles
You can obtain the SQL server data file and log file storage path.
5. Do some reverse operations after the execution, such as disabling xp_mongoshell, revoking shared credit relationships, and canceling folder sharing.