如何在控制台应用程序中提供地图网络驱动器路径

时间:2014-01-03 07:33:15

标签: c# sql console-application

我制作了一个控制台应用程序来备份Sql数据库,并将其存储到给定路径, 当我将此路径作为本地驱动器时,它工作正常,但是当我给出地图网络驱动器路径的路径时,意味着我想在其他网络PC中保存我的备份,它显示错误

  

无法打开备份设备   'Z:\ Smart_Tracker_03_01_2014_12_44_21_F_1_0.bak'。操作系统   错误3(系统找不到指定的路径。)。备份数据库   正在异常终止。

以下是我的代码:

Success_backup = Execute_Query_Master_Database("BACKUP DATABASE " + DatabaseName + " TO DISK = '" + Backup_FileName + "' ");
Success_Alter_DB = Execute_Query_Master_Database("ALTER DATABASE " + DatabaseName + "  SET MULTI_USER ");




public static  bool Execute_Query_Master_Database(string strQuery)
    {
        SqlConnection Conn = null;
        SqlCommand _command;

        {

            string connectionstring = @"Data Source=" + servername + ";Initial Catalog='master';User Id='" + UserName + "';Password='" + PassWord + "'";
            Conn = new SqlConnection(connectionstring);

            Conn.Open();
            _command = new SqlCommand();
            _command.Connection = Conn;
            _command.CommandType = CommandType.Text;
            _command.CommandText = strQuery;
            _command.CommandTimeout = 0;



            _command.ExecuteNonQuery();

            return true;


        }
        catch (Exception ex)
        {

            Console.WriteLine("Error occured in Function - Execute_Scaler_Master_Database()");
            Console.WriteLine("Error Message as below : ");
            Console.WriteLine("===========================");
            Console.WriteLine(ex.Message);
            Console.WriteLine();

            return false;
        }
        finally
        {
            _command = null;
            Conn.Close();

        }
    }

请注意,我传递了6个参数

      string[] args = new string[6];
        args[0] = "VARUN-PC"; //Sql Name
        args[1] = "Smart_Tracker"; //DataBase name
        args[2] = "sa"; // user Name
        args[3] = "admin@12"; // Password
        args[4] = "F"; // Backup type "F"mean full Backup here
        args[5] = @"Z:";  // path where to store database, here map drive

0 个答案:

没有答案
相关问题