Pervasive SQL System Stored Procedure from ADO.NET error

1.4k Views Asked by At

I'm just trying to return a list of columns and their attributes through a system stored procedure. What documentation I have seems to say the below code should work, but I get "Pervasive.Data.SqlClient.Lna.k: [LNA][Pervasive][ODBC Engine Interface]Invalid or missing argument." on the execute. This is PSQL v11, .NET 4.5.

using (PsqlConnection conn = new PsqlConnection(cs))
    {
        PsqlCommand locationCmd = new PsqlCommand();
        PsqlParameter tableParam = new PsqlParameter();
        PsqlParameter returnParam = new PsqlParameter();
        returnParam.Direction = ParameterDirection.ReturnValue;
        locationCmd.CommandText = "psp_columns";
        locationCmd.Connection = conn;
        locationCmd.CommandType = CommandType.StoredProcedure;
        locationCmd.Parameters.Add(tableParam).Value = table;
        locationCmd.Parameters.Add(returnParam);
        conn.Open();
        locationCmd.ExecuteNonQuery();

    }
4

There are 4 best solutions below

0
On

i was trying to figure this out as well, but with the tables procedure. even though the database and table names are optional, you still have to provide values. for optional parameters, pass in DBNull.Value

this worked for me:

PsqlCommand cm = new PsqlCommand();
cm.CommandText = "psp_tables";
cm.CommandType = CommandType.StoredProcedure;
cm.Connection = new PsqlConnection();
cm.Connection.ConnectionString = <your connection string>;
cm.Parameters.Add(":database_qualifier", DBNull.Value);
cm.Parameters.Add(":table_name", DBNull.Value);
cm.Parameters.Add(":table_type", "User table");
1
On

I would think the problem is this line:

  locationCmd.Parameters.Add(tableParam).Value = table;

You should set the value before adding the parameter, not afterwards.

  tableParam.Value = table;
  locationCmd.Parameters.Add(tableParam);

I don't know about Psql but for MSSQL normally you also need to define the parameter name as its found in the stored procedure, or at least that's what I do.

  SqlParameter param = new SqlParameter("@tableParam", value);
2
On

You should try to get the information of the table SCHEMA using the provided GetSchema method from the Psqlconnection. I have searched a bit on their support site and it seems that this method is supported although I haven't find a direct example using the Tables collection.

This is just an example adapted from a test on mine on SqlServer, I don't have Pervasive install, but you could try if the results are the same

using(PsqlConnection cn = new PsqlConnection("your connection string here"))
{
     cn.Open(); 
     string[] selection = new string[] { null, null, table }; 
     DataTable tbl = cn.GetSchema("Columns", selection); 
     foreach (DataRow row in tbl.Rows)
     { 
         Console.WriteLine(row["COLUMN_NAME"].ToString() + " " + 
                           row["IS_NULLABLE"].ToString() + " " +
                           row["DATA_TYPE"].ToString() 
         );
     } 
}
2
On

The psp_Columns system stored procedure is defined as call psp_columns(['database_qualifier'],'table_name', ['column_name']). I know that it says the database qualifier is optional, but I think it's required. You could try passing an empty string for the qualifier. Something like:

using (PsqlConnection conn = new PsqlConnection(cs))
    {
        PsqlCommand locationCmd = new PsqlCommand();
        PsqlParameter dbParam = new PsqlParameter();
        PsqlParameter tableParam = new PsqlParameter();
        PsqlParameter returnParam = new PsqlParameter();
        returnParam.Direction = ParameterDirection.ReturnValue;
        locationCmd.CommandText = "psp_columns";
        locationCmd.Connection = conn;
        locationCmd.CommandType = CommandType.StoredProcedure;

        locationCmd.Parameters.Add(dbParam).Value = ""; //might need two single quotes ('')
        locationCmd.Parameters.Add(tableParam).Value = table;
        locationCmd.Parameters.Add(returnParam);
        conn.Open();
        locationCmd.ExecuteNonQuery();

    }