温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - 42809 Error On Executing PostgreSQL Stored Procedure From Asp.Net C# Application
postgresql procedure npgsql

其他 - 从Asp.Net C#应用程序执行PostgreSQL存储过程时出现42809错误

发布于 2020-03-27 15:57:35

我正在将PostgreSQL pgadmin4(4.16v)与ASP.NET应用程序一起使用。我创建了一个定义如下的过程:

CREATE OR REPLACE PROCEDURE public.usp_bind(
    )
LANGUAGE 'plpgsql'

AS $BODY$
BEGIN
      select district_id,district_name from district_master order by district_name;
END;
$BODY$;

我从asp.net应用程序调用了上面的过程,代码如下:

NpgsqlConnection conn = new NpgsqlConnection();
        NpgsqlDataAdapter da = new NpgsqlDataAdapter();
        NpgsqlCommand cmd = new NpgsqlCommand();
        DataSet ds = new DataSet();
        public string dbconstr = dbConnectstr.Connectionstring();

        public DataSet getDatafunction(string procedure_, [Optional] string flag_)
        {
            using (conn = new NpgsqlConnection(dbconstr))
            {
                //conn.Open();
                using (da = new NpgsqlDataAdapter())
                {

                    da.SelectCommand.CommandType = CommandType.StoredProcedure;
                    da.SelectCommand.CommandText = "CALL usp_bind";
                    da.SelectCommand.Connection = conn;


                    using (ds = new DataSet())
                    {
                        da.Fill(ds);
                    }
                }
                //conn.Close();
            }
            return ds;
        }

它给我一个错误,因为-42809:'usp_bind'是一个过程。

我也可以使用一种CALL方法来调用它,但是没有用从ASP.NET应用程序调用过程的确切方法是什么?

查看更多

查看更多

提问者
Sumeet Kumar
被浏览
19
Shay Rojansky 2020-01-31 20:54

不要CommandType.StoredProcedure在您的命令上设置

不幸的是,存储过程是新的,并且CommandType.StoredProcedure已经被用来调用函数,而在这一点上进行更改将是一个重大的重大变化。