asp.net|server| Recovery | data | database
It is important to note that restore, restore time is the most problematic, the other users can not use the database to restore, the solution is to add a stored procedure in the master database:
Create proc killspid (@dbname varchar (20))
As
Begin
declare @sql nvarchar (500)
DECLARE @spid int
Set @sql = ' Declare getspid cursor for
Select spid from sysprocesses where dbid=db_id (' + @dbname + ') '
EXEC (@sql)
Open Getspid
FETCH NEXT from Getspid into @spid
While @ @fetch_status <>-1
Begin
EXEC (' kill ' + @spid)
FETCH NEXT from Getspid into @spid
End
Close Getspid
Deallocate getspid
End
Go
Execute this stored procedure before restoring, and you need to pass dbname, which is the name of your database. Below is the original code for the class: (The database connection string in Web.config is Constr)
Using System;
Using System.Configuration;
Using System.Data.SqlClient;
Using System.Data;
Namespace Web.base_class
{
<summary>
Dboper class, which primarily applies sqldmo to backup and restore Microsoft SQL Server databases
<summary>
public class Dboper
{
private string server;
private string uid;
private string pwd;
private string database;
private String Conn;
<summary>
Constructors for Dboper classes
<summary>
Public Dboper ()
{
conn=system.configuration.configurationsettings.appsettings["Constr"]. ToString ();
Server=cut (conn, "server=", ";");
Uid=cut (conn, "uid=", ";");
Pwd=cut (conn, "pwd=", ";");
Database=cut (conn, "database=", ";");
}
public string Cut (String str,string bg,string ed)
{
String Sub;
Sub=str. Substring (str. INDEXOF (BG) +bg. Length);
Sub=sub. Substring (0,sub. IndexOf (";"));
return sub;
}
[1] [2] Next page