I am trying to execute a stored procedure through C #, ADO.NET and below - this is the code I am trying to execute:
using (SqlConnection conn = new SqlConnection(".;Initial Catalog=MyDB;User ID=sa;Password=***"))
{
try
{
string cmdText = "dbo.sp_Create_FlaggedItemEntry @URI, @ID";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = cmdText;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@URI", value1);
cmd.Parameters.AddWithValue("@ID", value2);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}
Now, when I try to debug it, I got an error message in the line - cmd.ExecuteNonQuery();- "Could not find the stored procedure dbo.sp_Create_FlaggedItemEntry"
I checked that the connection string is correct and that the stored procedure exists. In addition, if I change the line - cmd.CommandType = CommandType.StoredProcedure;to cmd.CommandType = CommandType.Text; it runs successfully and as expected.
Can someone tell me what I don’t see and am doing wrong here? Please forgive me if this is something very simple, since I have been working with ADO.NET for a long time