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. General Programming
  3. C#
  4. an exception with this code

an exception with this code

Scheduled Pinned Locked Moved C#
databasesql-serversysadminhelpquestion
11 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 Mohamed El Wehishy

    hi guys when i run this code it throw an exception but it run well inside SQL Server 2008

    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

    so what is the problem thanks, Mohamed El-Wehishy

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

    Mohamed El-Wehishy wrote:

    when i run this code

    What do you mean? Run it where/how?

    Mohamed El-Wehishy wrote:

    it throw an exception

    What exception?


    only two letters away from being an asset

    M 1 Reply Last reply
    0
    • M Mohamed El Wehishy

      hi guys when i run this code it throw an exception but it run well inside SQL Server 2008

      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

      so what is the problem thanks, Mohamed El-Wehishy

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      Don't you think maybe this belongs in the Database section as opposed to the C# section?

      Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]

      1 Reply Last reply
      0
      • M Mohamed El Wehishy

        hi guys when i run this code it throw an exception but it run well inside SQL Server 2008

        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

        so what is the problem thanks, Mohamed El-Wehishy

        M Offline
        M Offline
        Md Marufuzzaman
        wrote on last edited by
        #4

        You should post it to the General Database forum..:)

        Thanks Md. Marufuzzaman


        Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

        1 Reply Last reply
        0
        • N Not Active

          Mohamed El-Wehishy wrote:

          when i run this code

          What do you mean? Run it where/how?

          Mohamed El-Wehishy wrote:

          it throw an exception

          What exception?


          only two letters away from being an asset

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

          ok man this is my code

          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");
                  }
              }
          

          when i run this code it throw exception 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

          N 1 Reply Last reply
          0
          • M Mohamed El Wehishy

            ok man this is my code

            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");
                    }
                }
            

            when i run this code it throw exception 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

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

            Read the previous response. What is the exception that is being thrown????


            only two letters away from being an asset

            L 1 Reply Last reply
            0
            • N Not Active

              Read the previous response. What is the exception that is being thrown????


              only two letters away from being an asset

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

              why, WrongForumException, the most popular of all; what else could it be? :)

              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 N 2 Replies Last reply
              0
              • L Luc Pattyn

                why, WrongForumException, the most popular of all; what else could it be? :)

                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
                #8

                hi guys please redirect me to a link or tutorial which help me i can not understand the reason thanks Mohamed El-Wehishy

                N 1 Reply Last reply
                0
                • M Mohamed El Wehishy

                  hi guys please redirect me to a link or tutorial which help me i can not understand the reason thanks Mohamed El-Wehishy

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

                  You can't understand the reason for what? You still haven't given any useful information


                  only two letters away from being an asset

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    why, WrongForumException, the most popular of all; what else could it be? :)

                    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!


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

                    I wouldn't say that. The original post should have made in clearer, but it does appear to be C# related question. If he/she could only understand what an exception is, we'll all know more.


                    only two letters away from being an asset

                    L 1 Reply Last reply
                    0
                    • N Not Active

                      I wouldn't say that. The original post should have made in clearer, but it does appear to be C# related question. If he/she could only understand what an exception is, we'll all know more.


                      only two letters away from being an asset

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

                      You're right. While the OP started with SQL in the C# forum, it now figures in the DB forum showing C# code; and we may be about to find out what the exception is. :)

                      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
                      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