易截截图软件、单文件、免安装、纯绿色、仅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 4.0的七大新特性之"控件的ClientIDMode"


 在早期的ASP.NET框架中,如果你放置一个控件在一个容器中,如GridView模板列、登录模板、其它,在运行时这些控件的ID将被替换由ASP.NET自身产生的随机唯一ID。
      
      为开发者提供服务方访问控件的Page.FindControl("controlid")以及JavaScript中使用 的document ......

C# ASP.NET里@的妙用

C# ASP.NET里@的妙用
ASP.NET C# string 字符串的前面可以加 @ 可以将转义字符(\)当作普通字符对待。
比如:string str = @"C:\Windows";
如果我们不用 @ 的话,应该是:string str = "C:\\Windows";
 
@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3 ......

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 ......

java数据库连接及测试(sqlserver)


package com.test.util;
import java.sql.*;
public class ConnectDB {
 private Connection conn=null;
 private PreparedStatement pt=null;
 private ResultSet rs=null;
 private String uname="sa";
 private String upwd="sa";
 private String url="jdbc:microsoft:sqlserv ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号