错误“无法找到存储过程'Procedure_name'" [英] Error "Could not find stored procedure 'Procedure_name'"

查看:109
本文介绍了错误“无法找到存储过程'Procedure_name'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行storeprocedure抛出Ado.net时,我面临以下错误,



错误无法找到存储过程'Procedure_name'



SP包含输出参数如果我删除输出参数我将正常工作。



此处我附加了Storeprocedure和Ado.net连接编码



存储过程



When i try execute the storeprocedure throw Ado.net i am facing the following error,

Error "Could not find stored procedure 'Procedure_name'"

that SP contain output Parameter if i remove output parameter i will work fine .

Herewith i have attached the Storeprocedure and Ado.net connectivty coding

Store Procedure

create PROCEDURE [dbo].[USP_CreateCatagory]
    -- Add the parameters for the stored procedure here
    @CatagoryName Varchar(50),
    @CatagoryId int out

AS
BEGIN
   
    Insert into tblCategory(categoryName) Values (@CatagoryName)
    select  @CatagoryId = SCOPE_IDENTITY()
END





Ado.Net





Ado.Net

sqlCon = new SqlConnection(SqlConnectionString);
            sqlcmd = new SqlCommand("USP_CreateCatagory", sqlCon);
            try
            {
                sqlcmd.CommandType = CommandType.StoredProcedure;

                sqlCon.Open();
            SqlParameter CatagoryName11 = new SqlParameter();
            CatagoryName11.ParameterName = "CatagoryName";
            CatagoryName11.Value = CategoryName;
            CatagoryName11.SqlDbType = SqlDbType.VarChar;
            CatagoryName11.Direction = ParameterDirection.Input;

            SqlParameter oUtputParam = new SqlParameter();
            oUtputParam.ParameterName = "@CatagoryId";
            oUtputParam.SqlDbType = SqlDbType.Int;
            oUtputParam.Direction = ParameterDirection.Output;               

             sqlcmd.Parameters.Add(CatagoryName11);

             sqlcmd.Parameters.Add(oUtputParam);

                sqlcmd.ExecuteNonQuery();
                sqlcmd.Dispose();
                sqlCon.Close();





----------------- ------------------



我在sqlcmd.ExecuteNonQuery();



-----------------------------------

I am facing error in "sqlcmd.ExecuteNonQuery();"

推荐答案

在打开 sqlcon sqlcmd 是否重要? >?



我建议您在创建 sqlcmd 对象之前执行数据库的打开。



此外,类别中只有一个a。
Does it matter that you instantiate sqlcmd before you open sqlcon?

I suggest you execute the open of the database before you create the sqlcmd object.

Also, there is only one "a" in category.


您的代码可以正常工作。您需要检查Valery Possoz提到的那些项目是否正确。如果你想要Dispose(),不仅Close(),或许,这样构造更好:

Your code could work. You need to check whether those items Valery Possoz mentioned are correct. And if you want to "Dispose()", not only "Close()", perhaps, to construct like this is better:
using (SqlConnection sqlCon = new SqlConnection(SqlConnectionString))
{
    SqlCommand sqlcmd = sqlCon.CreateCommand();

    sqlcmd.CommandType = CommandType.StoredProcedure;
    sqlcmd.CommandText = "USP_CreateCatagory";

    SqlParameter CatagoryName11 = new SqlParameter
    {
        ParameterName = "CatagoryName",
        Value = CategoryName,
        SqlDbType = SqlDbType.VarChar,
        Direction = ParameterDirection.Input
    };

    SqlParameter oUtputParam = new SqlParameter
    {
        ParameterName = "@CatagoryId",
        SqlDbType = SqlDbType.Int,
        Direction = ParameterDirection.Output
    };

    sqlcmd.Parameters.Add(CatagoryName11);
    sqlcmd.Parameters.Add(oUtputParam);

    try
    {
        sqlCon.Open();
        sqlcmd.ExecuteNonQuery();
    }
    catch { }
}


这篇关于错误“无法找到存储过程'Procedure_name'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆