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. need sp_helpdb return values

need sp_helpdb return values

Scheduled Pinned Locked Moved C#
csharpsharepointhelptutorialquestion
7 Posts 3 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.
  • B Offline
    B Offline
    betterc
    wrote on last edited by
    #1

    I've learned how to connect, attach and detach my msde tables and databases. Now I need to be able to make a call to sp_helpdb and get the return values from a C# applicaiton. Can someone give me some help please? Thanks, cb

    L H 2 Replies Last reply
    0
    • B betterc

      I've learned how to connect, attach and detach my msde tables and databases. Now I need to be able to make a call to sp_helpdb and get the return values from a C# applicaiton. Can someone give me some help please? Thanks, cb

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Look at this week's articles :) top secret xacc-ide 0.0.1

      B 2 Replies Last reply
      0
      • L leppie

        Look at this week's articles :) top secret xacc-ide 0.0.1

        B Offline
        B Offline
        betterc
        wrote on last edited by
        #3

        Where?

        1 Reply Last reply
        0
        • L leppie

          Look at this week's articles :) top secret xacc-ide 0.0.1

          B Offline
          B Offline
          betterc
          wrote on last edited by
          #4

          I think his article is good for creating wrappers for stored procedures that have been created for a given db. But my question is specifically about sp_helpdb. How would you construct c# code to execute this sp and get it's returned value(s)???? cb

          1 Reply Last reply
          0
          • B betterc

            I've learned how to connect, attach and detach my msde tables and databases. Now I need to be able to make a call to sp_helpdb and get the return values from a C# applicaiton. Can someone give me some help please? Thanks, cb

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            The same as you do for any stored procedure: create a SqlCommand and fill it's Parameters collection property with parameters using the same names as the parameters defined by the stored procedure, plus one parameter with a direction of ParameterDirection.ReturnValue:

            SqlCommand cmd = connection.CreateCommand();
            cmd.CommandText = "sp_helpdb";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@dbname", SqlDbType.NVarChar, 128).Value = "master";
            SqlParameter retVal = new SqlParameter("@RETURN_VALUE", SqlDbType.NVarChar,
            128, ParameterDirection.ReturnValue, false, 0, 0, null,
            DataRowVersion.Current, null);
            cmd.Parameters.Add(retVal);
            try
            {
            connection.Open();
            cmd.ExecuteNonQuery();
            }
            finally
            {
            connection.Close();
            }
            Console.WriteLine(retVal.Value);

            Microsoft MVP, Visual C# My Articles

            B 1 Reply Last reply
            0
            • H Heath Stewart

              The same as you do for any stored procedure: create a SqlCommand and fill it's Parameters collection property with parameters using the same names as the parameters defined by the stored procedure, plus one parameter with a direction of ParameterDirection.ReturnValue:

              SqlCommand cmd = connection.CreateCommand();
              cmd.CommandText = "sp_helpdb";
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@dbname", SqlDbType.NVarChar, 128).Value = "master";
              SqlParameter retVal = new SqlParameter("@RETURN_VALUE", SqlDbType.NVarChar,
              128, ParameterDirection.ReturnValue, false, 0, 0, null,
              DataRowVersion.Current, null);
              cmd.Parameters.Add(retVal);
              try
              {
              connection.Open();
              cmd.ExecuteNonQuery();
              }
              finally
              {
              connection.Close();
              }
              Console.WriteLine(retVal.Value);

              Microsoft MVP, Visual C# My Articles

              B Offline
              B Offline
              betterc
              wrote on last edited by
              #6

              I entered the code as you suggested and it works returning a '0'. My questions is how do I 'get' the values such as the name/path of the db and log files? Thank you, c

              H 1 Reply Last reply
              0
              • B betterc

                I entered the code as you suggested and it works returning a '0'. My questions is how do I 'get' the values such as the name/path of the db and log files? Thank you, c

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                Sorry, I was thinking of a different stored proc. Handle the SqlConnection.InfoMessage event. This gets you the text that is printed using the PRINT statement in SQL (among other things). This is what sp_helpdb uses to print the information about whatever database name you passed as a parameter.

                Microsoft MVP, Visual C# My Articles

                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