Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I made one console application which take backup of Sql database, and store it to given path,
It works perfect when i give this path as local Drive, But when i give path to map network drive path, means i want to save my backup in other network pc, it show error

Cannot open backup device
'Z:\Smart_Tracker_03_01_2014_12_44_21_F_1_0.bak'. Operating system
error 3(The system cannot find the path specified.). BACKUP DATABASE
is terminating abnormally.


Below is my code:

C#
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();
             
            }
        }

Kindly noted I pass 6 arguments



C#
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
Posted
Comments
ArunRajendra 3-Jan-14 3:32am    
Did you check if you have write permission to mapped drive?

You need to map the drive on the system (not via code).
 
Share this answer
 
You will need to provide complete location. As in \\serverName\Folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900