I have a data base (NewYekAye) in sql server with some tables and stored procedures. one of the tables is TbSoore and one of the stored procedures is spGetSoore.
I created spGetSoore whith this codes:
USE [NewYekAye]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[spGetSoore]
@IdSoore INT
As
Begin
SELECT IdSoore, NameSoore, MakiMadani, TextMoghadame, TextHadis, TextMohtava, TextMoarefi FROM TbSoore WHERE (StutusSoore = 1) AND (IdSoore = @IdSoore)
End
Go
and in C# code use it with:
string strsql =
$@"EXEC spGetSoore @IdSoore = @IdSoore;";
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(strcon))
{
using
(SqlCommand cmdSQL = new SqlCommand(strsql, con))
{
cmdSQL.CommandType = CommandType.StoredProcedure;
cmdSQL.Parameters.Add(new SqlParameter ("@IdSoore", forwardedIdSoore)) ;
con.Open();
dt.Load(cmdSQL.ExecuteReader());
}
}
but when I run the site, I get this error:
Exception Details: System.Data.SqlClient.SqlException: Could not find stored procedure ‘EXEC spGetSoore @IdSoore = @IdSoore’.
I checked my sql connection in c# by using SELECT IdSoore, NameSoore, MakiMadani, TextMoghadame, TextHadis, TextMohtava, TextMoarefi FROM TbSoore WHERE (StutusSoore = 1) AND (IdSoore = @IdSoore)
query instead Exec spGetSoore
and worked.
then run Exec spGetSoore
in sql server query and worked too.
Of course in sql server when I wrote EXEC spGetSoore @IdSoore = 1;
,showed red underline for spGetSoore
with this tooltip:
Could not found stored procedure ‘spGetSoore’.
but worked!!
like this:
but I don’t know why I got this error and what I can fix it.
Please help me.