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?
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);
}
cmdandsbwithout utilizing them, they can probably be removed. You should probably declare the command's CommandText to be the name of your Stored Procedure, and set the CommandType to CommandType.StoredProcedure, then add the path value as a SqlParameter to the command.