与我本机在同一网段的另外一台计算机上,创建一个文件夹,名aa,设置其为web共享,everyone可读写权限。在我本地运行程序,代码如下。  using  System;  
using  System.Data;  
using  System.Configuration;  
using  System.Collections;  
using  System.Web;  
using  System.Web.Security;  
using  System.Web.UI;  
using  System.Web.UI.WebControls;  
using  System.Web.UI.WebControls.WebParts;  
using  System.Web.UI.HtmlControls;  
using  System.Data.SqlClient;  
//using  System.Configuration;  
using  Suzsoft.CMS;  
 
 
public  partial  class  UI_SystemManager_SysBackupAndRestore_BackupRestore  :  PageBase  
{  
       string  ConnStr                    =  System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer1"];  
 
       string  strDataBaseName    =  "Northwind";    //保存的数据库名称  
 
       protected  void  Page_Load(object  sender,  EventArgs  e)  
       {  
               if  (!IsPostBack)  
               {  
                       DataBaseName.Text  =  strDataBaseName.ToString();  
               }  
       }  
 
       ///  <summary>  
       ///  Backup  the  database  
       ///  </summary>  
       ///  <param  name="sender"></param>  
       ///  <param  name="e"></param>  
       protected  void  backupButton_Click(object  sender,  System.EventArgs  e)  
       {  
   
               ParamValueDAL  ds                  =  new  ParamValueDAL();  
               if(ds.SelectDataBasePath().Tables[0].Rows.Count<=0)  
               {  
                       Response.Write("<script>alert('对不起,您还未配置数据库保存及还原路径的参数值!')</script>");  
                       return;  
               }  
               else  
               {  
                       string  path                    =  ds.SelectDataBasePath().Tables[0].Rows[0][0].ToString()  +  strDataBaseName.ToString()+  ".bak";      \\这里的SelectDataBasePath()可取到程序中设置好的备份路径"\\192.168.0.2\aa"  
 
                       string  dbname                =  strDataBaseName.ToString();  
                       string  backupSql          =  "use  master;";  
                       backupSql  +=  "backup  database  @dbname  to  disk  =  @path;";  
 
                       SqlCommand  myCommand  =  new  SqlCommand(backupSql,  new  SqlConnection(ConnStr));  
 
                       myCommand.Parameters.Add("@dbname",  SqlDbType.Char);  
                       myCommand.Parameters["@dbname"].Value  =  dbname;  
                       myCommand.Parameters.Add("@path",  SqlDbType.Char);  
                       myCommand.Parameters["@path"].Value      =  path;  
 
                       try  
                       {  
                               myCommand.Connection.Open();  
                               myCommand.ExecuteNonQuery();  
                               infoLabel.Text  =  "  备份成功!";  
                       }  
                       catch  (Exception  ex)  
                       {  
                               infoLabel.Text  =  "  备份失败!  备份路径或该数据库不存在!"    ;  
                       }  
                       finally  
                       {  
                               myCommand.Connection.Close();  
                       }  
               }  
                         
       }  
         
       ///  <summary>  
       ///  Restore  the  database  
       ///  </summary>  
       ///  <param  name="sender"></param>  
       ///  <param  name="e"></param>  
       protected  void  restoreButton_Click(object  sender,  System.EventArgs  e)  
       {  
               ParamValueDAL  ds                  =  new  ParamValueDAL();  
               if  (ds.SelectDataBasePath().Tables[0].Rows.Count  <=  0)  
               {  
                       Response.Write("<script>alert('对不起,您还未配置数据库保存及还原路径的参数值!')</script>");  
                       return;  
               }  
               else  
               {  
                       string  path                    =  ds.SelectDataBasePath().Tables[0].Rows[0][0].ToString()  +  strDataBaseName.ToString()  
                                                                 +  ".bak";  
 
                       string  dbname  =  strDataBaseName.ToString();  
                       string  restoreSql        =  "use  master;";  
                       restoreSql  +=  "restore  database  @dbname  from  disk  =  @path;";  
 
                       SqlCommand  myCommand  =  new  SqlCommand(restoreSql,  new  SqlConnection(ConnStr));  
 
                       myCommand.Parameters.Add("@dbname",  SqlDbType.Char);  
                       myCommand.Parameters["@dbname"].Value  =  dbname;  
                       myCommand.Parameters.Add("@path",  SqlDbType.Char);  
                       myCommand.Parameters["@path"].Value      =  path;  
 
                       try  
                       {  
                               myCommand.Connection.Open();  
                               myCommand.ExecuteNonQuery();  
                               infoLabel.Text  =  "  恢复成功!";  
                       }  
                       catch  (Exception  ex)  
                       {  
                               infoLabel.Text  =  "  恢复失败!  还原数据库文件不存在!";  
                       }  
                       finally  
                       {  
                               myCommand.Connection.Close();  
                       }  
               }  
                         
       }  
}  

解决方案 »

  1.   

    ?web共享  ,应该是域用户共享吧
      
    *****************************************************************************
    欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码) 
    http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    异地文件夹是web共享并设有everyone完全权限 没错 也是异地共享 我现在用SQL2000 现在都不知道以技术层面来说 是否目前能做异地备份 除了流操作没做过之外 我都试过了 有人做成功吗?
      

  3.   

    catch  (Exception  ex)  
    看看什么错误