none
running DB backup procedure in C# RRS feed

  • Question

  • Hi,
        I have a MS SQL stored procedure to backup a DB. i want to execute it in C#. I tried using ExecuteNonQuery, but it didnt work. here's my code:

    private bool runStoredProcedure()
            {
                int t = 0;
                SqlConnection conn = Connection.getConnection();
                try
                {
                    SqlCommand cmd = new SqlCommand("dbBackup", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@Path", @"c:\"));
                    cmd.Parameters.Add(new SqlParameter("@DBName", "Northwind"));
                    t = cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }

                conn.Close();

                if (t > 0)
                    return true;
                else
                    return false;
            }

    dbBackup is the name of the procedure. All help appreciated.


    Wednesday, September 5, 2007 7:04 AM

All replies