title: how to check if stored procedure exists or not in sql server using c# code
body: <p>I tried below code for cheking SP is alredy exist or not. if not exist i am creating..</p>
  
  <p>But every time it is showing sp is not created.....But my database already have this sp.</p>
  
  <p>Let me know where i am doing mistake.</p>
  
  <pre><code>string checkSP = String.Format(
    "IF OBJECT_ID('{0}', 'U') IS NOT NULL SELECT 'true' ELSE SELECT 'false'", 
    "GP_SOP_AdjustTax");
  
  SqlCommand command = new SqlCommand(checkSP, myConnection);
  command.CommandType = CommandType.Text;
  
  if (myConnection == null || myConnection.State == ConnectionState.Closed)
  {
      try
      {
          myConnection.Open();
      }
      catch (Exception a)
      {
          MessageBox.Show("Error " + a.Message);
      }
  }
  
  bool Exist = false;
  Exist = Convert.ToBoolean(command.ExecuteScalar());
  if (Exist == false)   //false : SP does not exist
  { 
      // here i am writing code for creating SP
  }
  </code></pre>