Emanuele Mazzoni
Emanuele Mazzoni

Reputation: 716

Error calling function postgresql .NET

ERROR: 42883: function insertvideo(character varying, character varying, double precision, integer) does not exist

But that Stored Procedure exist!!! Why continue this error???

This is my connection string:

 <connectionStrings>
        <add name="myConnection" connectionString="Server=127.0.0.1; 
                   User Id=postgres; Password=myPass; Database=myDB; "/>
      </connectionStrings>

Stored Procedure is in public schema and work correctly.

    using (NpgsqlConnection conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["AxWaveConnection"].ToString()))
    {
        try
        {
            conn.Open();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        NpgsqlCommand cmd = new NpgsqlCommand("insertvideo", conn);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;


        cmd.Parameters.Add(new NpgsqlParameter("out_scope_id", NpgsqlDbType.Bigint));
            cmd.Parameters["out_scope_id"].Direction = ParameterDirection.Output;

        cmd.Parameters.Add(new NpgsqlParameter("in_youtubeidvideo", NpgsqlDbType.Varchar, 15));
        cmd.Parameters["in_youtubeidvideo"].Value = VideoId;

        cmd.Parameters.Add(new NpgsqlParameter("in_title", NpgsqlDbType.Varchar, 200));
        cmd.Parameters["in_title"].Value = Title;

        cmd.Parameters.Add(new NpgsqlParameter("in_rating", NpgsqlDbType.Double));
        cmd.Parameters["in_rating"].Value = Rating;

        cmd.Parameters.Add(new NpgsqlParameter("in_viewcount", NpgsqlDbType.Integer));
        cmd.Parameters["in_viewcount"].Value = ViewCount;


        try
        {
            cmd.ExecuteNonQuery();

            scopeID = Convert.ToInt64(cmd.Parameters["out_scope_id"].Value);
        }
        catch (Exception e)
        {
            scopeID = -1;        //Duplicate Record
        }

        conn.Close();

Upvotes: 1

Views: 3414

Answers (3)

Nitin Aggarwal
Nitin Aggarwal

Reputation: 461

Please add below connection string

<connectionStrings>
            <add name="myConnection" connectionString="Server=127.0.0.1; 
                       User Id=postgres; Password=myPass; Database=myDB; " providerName="postgre"/>
          </connectionStrings>

Upvotes: 0

John Woo
John Woo

Reputation: 263683

You cannot pass function in NpgsqlCommand command object. The only allowed there is sql query or the name of the stored procedure.

The best way to do is to create a STORED PROCEDURE with the function inside it and call the procedure in ado.net.

Upvotes: 0

Muthuram
Muthuram

Reputation: 154

Server=127.0.0.1; add name="ConnectionStringName" connectionString="server=ServerNameOrIP;database=DataBasename;uid=UserID;pwd=Password; Check this Correctly an try again. It will work. Database connection not established.

Upvotes: 1

Related Questions