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
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
\\serverName\Folder
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)