易截截图软件、单文件、免安装、纯绿色、仅160KB

用asp.net还原与恢复sqlserver数据库

  
上次做了个项目,涉及到数据库的还原和恢复,到网上找了一下,是利用SQLDMO实现的,只要添加SQLDMO引用就好了,然后利用下边的类的方法就可以实现了。
我把原作者的类扩充了一下,可以自动识别web.config里 的数据库连接字符串,可以通过变量设置还原恢复的信息。
需要注意的时还原,还原的时候问题最大了,有别的用户使用数据库的时候无法还原,解决办法就是在MASTER数据库中添加一个存储过程:
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
在还原之前先执行这个存储过程,需要传递dbname,就是你的数据库的名字。下边是类的原代码:(web.config里的数据库连接字符串是constr)
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace web.base_class
{
     /// <summary>
     /// DbOper类,主要应用SQLDMO实现对Microsoft SQL Server数据库的备份和恢复
     /// </summary>
     public class DbOper
     {
          private string server;
          private string uid;
          private string pwd;
          private string database;
  


相关文档:

ASP.NET技术的学习顺序问题

前前后后收到过一些学生的来信,询问ASP.NET的学习顺序问题,在此就向打算系统学习ASP.NET技术的初学者谈谈我的建议。
 
如果你已经有较多的面向对象开发经验,跳过以下这两步:
第一步 掌握一门.NET面向对象语言,C#或VB.NET。
       我强烈反对在没系统学过一门面向对象(OO) ......

Asp.Net Button的UseSubmitBehavior属性

在某页面上有如下信息,
Html,
<asp:Button ID="btn" runat="server" Text="Click me" OnClick="ButtonClicked" />
<script language="javascript">
function javascriptMethod() {
alert(1);
}

</script>
C#,
protected void ButtonClic ......

Javascript 在ASP.net 母板页下访问 控件ID:

Javascript 在ASP.net 母板页下访问 控件ID:
对于 html control : 直接访问ID
document.getElementById("hfRespondID");
对于 Web control :
document.getElementById("<%= this.hfRespondID.ClientID %>") [注意大小写
]     
     &nb ......

asp.net 导出Excel

public bool SaveExcel(GridView paramGridView)
{
if (paramGridView.Rows.Count == 0)
{
return false;
}
//创建Excel对象
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.Appl ......

Sqlserver 中临时表和全局临时表

SQL Server 支持临时表。临时表就是那些名称以井号 (#) 开头的表。如果当用户断开连接时没有除去临时表,SQL Server 将自动除去临时表。临时表不存储在当前数据库内,而是存储在系统数据库 tempdb 内。
临时表有两种类型: 
本地临时表 
以一个井号 (#) 开头的那些表名。只有在创建本地临时表的连接上才能看 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号