title: Executing a SQL Server stored procedure from C#
body: <p>I have problems executing my stored procedure in C# console application and I don't know what the problem is. Could you please take a look?</p>
  
  <pre><code>string path="";
  
  StringBuilder sb = new StringBuilder();
  StringBuilder sqlErrorMessages = new StringBuilder("Sql Exception:\n");
  
  try
  { 
      SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M3IMRLE\\SQLEXPRESS; Initial Catalog = db2; Integrated security=true");
  
      Console.WriteLine("Enter path : ");
      path = Console.ReadLine();
      conn.Open();
  
      SqlCommand cmd = new SqlCommand();
  
      SqlCommand command = new SqlCommand("EXECUTE main.mainproc @path='" + path + "'", conn);
  
      if(command!=null)
      { 
          Console.WriteLine("JSON loaded");
      }  
  
      conn.Close();
  }
  catch(SqlException ex)
  {
      sqlErrorMessages.AppendFormat("Message: {0}\n", ex.Message);
  }
  </code></pre>