国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

用ASP.NET還原與恢復(fù)SQL Server數(shù)據(jù)庫(kù)

2024-07-10 13:03:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

需要注意的是還原,還原的時(shí)候問(wèn)題最大了,有別的用戶(hù)使用數(shù)據(jù)庫(kù)的時(shí)候無(wú)法還原,解決辦法就是在master數(shù)據(jù)庫(kù)中添加一個(gè)存儲(chǔ)過(guò)程:

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('''[email protected]+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status<>-1
begin
exec('kill '[email protected])
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end
go

在還原之前先執(zhí)行這個(gè)存儲(chǔ)過(guò)程,需要傳遞dbname,就是你的數(shù)據(jù)庫(kù)的名字。下邊是類(lèi)的原代碼:(web.config里的數(shù)據(jù)庫(kù)連接字符串是constr)

using system;

using system.configuration;

using system.data.sqlclient;

using system.data;

namespace web.base_class

{

/// <summary>



/// dboper類(lèi),主要應(yīng)用sqldmo實(shí)現(xiàn)對(duì)microsoft sql server數(shù)據(jù)庫(kù)的備份和恢復(fù)

/// <summary>


public class dboper

{

private string server;

private string uid;

private string pwd;

private string database;

private string conn;

/// <summary>


/// dboper類(lèi)的構(gòu)造函數(shù)

/// <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;

}

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石狮市| 澄江县| 河南省| 娄底市| 秦安县| 仪征市| 收藏| 河间市| 武陟县| 河间市| 平阳县| 高清| 江津市| 乳源| 柏乡县| 武陟县| 西丰县| 桐城市| 静海县| 鸡泽县| 孝义市| 遂平县| 赫章县| 嘉定区| 新竹市| 鄢陵县| 雷波县| 海原县| 娱乐| 吉林市| 太湖县| 兰考县| 买车| 瓦房店市| 巴东县| 甘泉县| 定襄县| 虞城县| 黑水县| 大港区| 郁南县|