Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. it is wrong with this

it is wrong with this

Scheduled Pinned Locked Moved Database
databasesysadminsecurityquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohamed El Wehishy
    wrote on last edited by
    #1

    this code throw exception hi guys when i run the next code it throw an exception

    private void button1_Click(object sender, EventArgs e)
    {
    try
    {
    SqlConnection cn = new SqlConnection("initial catalog=vvvvvvvvvvv;server=.;integrated security=sspi");
    SqlCommand cmd = new SqlCommand("back_up_database", cn);
    cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();
    
                int i = cmd.ExecuteNonQuery();
    
                cn.Close();
    
    
    
                if (i > 0)
                {
                    MessageBox.Show("Your database is backed up");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Sorry we can not back up your database");
            }
        }
    

    but when i execute the stored procedure

    ALTER proc [dbo].[back_up_database]
    as
    ALTER DATABASE [vvvvvvvvvvv]
    SET OFFLINE
    go
    BACKUP DATABASE [vvvvvvvvvvv]
    TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
    with NO_COMPRESSION
    go
    ALTER DATABASE [vvvvvvvvvvv]
    SET ONLINE
    go

    it completed successfully so what is wrong thanks for your interest Mohamed El-Wehishy

    I 1 Reply Last reply
    0
    • M Mohamed El Wehishy

      this code throw exception hi guys when i run the next code it throw an exception

      private void button1_Click(object sender, EventArgs e)
      {
      try
      {
      SqlConnection cn = new SqlConnection("initial catalog=vvvvvvvvvvv;server=.;integrated security=sspi");
      SqlCommand cmd = new SqlCommand("back_up_database", cn);
      cmd.CommandType = CommandType.StoredProcedure;

                  cn.Open();
      
                  int i = cmd.ExecuteNonQuery();
      
                  cn.Close();
      
      
      
                  if (i > 0)
                  {
                      MessageBox.Show("Your database is backed up");
                  }
              }
              catch(Exception ex)
              {
                  MessageBox.Show("Sorry we can not back up your database");
              }
          }
      

      but when i execute the stored procedure

      ALTER proc [dbo].[back_up_database]
      as
      ALTER DATABASE [vvvvvvvvvvv]
      SET OFFLINE
      go
      BACKUP DATABASE [vvvvvvvvvvv]
      TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
      with NO_COMPRESSION
      go
      ALTER DATABASE [vvvvvvvvvvv]
      SET ONLINE
      go

      it completed successfully so what is wrong thanks for your interest Mohamed El-Wehishy

      I Offline
      I Offline
      i j russell
      wrote on last edited by
      #2

      Have you looked at the exception?

      M I 2 Replies Last reply
      0
      • I i j russell

        Have you looked at the exception?

        M Offline
        M Offline
        Mohamed El Wehishy
        wrote on last edited by
        #3

        i can not understand you man please explain your words i want to know why this exception throwed thanks for help Mohamed El-Wehishy

        L 1 Reply Last reply
        0
        • M Mohamed El Wehishy

          i can not understand you man please explain your words i want to know why this exception throwed thanks for help Mohamed El-Wehishy

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Mohamed El-Wehishy wrote:

          this exception

          what exception? :~

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          Local announcement (Antwerp region): Lange Wapper? Neen!


          M 1 Reply Last reply
          0
          • L Luc Pattyn

            Mohamed El-Wehishy wrote:

            this exception

            what exception? :~

            Luc Pattyn


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            Local announcement (Antwerp region): Lange Wapper? Neen!


            M Offline
            M Offline
            Mohamed El Wehishy
            wrote on last edited by
            #5

            you can see the first message i wait your response thanks Mohamed El-Wehishy

            L 1 Reply Last reply
            0
            • M Mohamed El Wehishy

              you can see the first message i wait your response thanks Mohamed El-Wehishy

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Your code contains:

              catch(Exception ex)
              {
              MessageBox.Show("Sorry we can not back up your database");
              }

              which is moronic, the ex variable contains a lot of information, which you should look at by showing it, say with Console.WriteLine(ex.ToString()); and instead you ignore it and then ask the world what is wrong?????????????????????????????????????????????????????????????????? :|

              Luc Pattyn


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              Local announcement (Antwerp region): Lange Wapper? Neen!


              1 Reply Last reply
              0
              • I i j russell

                Have you looked at the exception?

                I Offline
                I Offline
                i i i
                wrote on last edited by
                #7

                comment try and catch and see what message it gives as error or you can write ex.message also to see the exception message

                Best Of Regards, SOFTDEV If you have knowledge, let others light their candles at it

                N 1 Reply Last reply
                0
                • I i i i

                  comment try and catch and see what message it gives as error or you can write ex.message also to see the exception message

                  Best Of Regards, SOFTDEV If you have knowledge, let others light their candles at it

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  Or he could just learn to debug the code by setting a breakpoint.


                  only two letters away from being an asset

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups