简体   繁体   English

来自ADO.NET的普遍SQL系统存储过程错误

[英]Pervasive SQL System Stored Procedure from ADO.NET error

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." 我似乎在说什么文档,下面的代码应该起作用,但是我得到“ Pervasive.Data.SqlClient.Lna.k:[LNA] [Pervasive] [ODBC Engine Interface]无效或缺少参数。” on the execute. 在执行。 This is PSQL v11, .NET 4.5. 这是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();

    }

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. 我不了解Psql,但是对于MSSQL,通常您还需要将参数名称定义为在存储过程中找到的名称,至少这是我要做的。

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

You should try to get the information of the table SCHEMA using the provided GetSchema method from the Psqlconnection. 您应该尝试使用Psqlconnection提供的GetSchema方法获取表SCHEMA的信息。 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. 我在他们的支持站点上进行了一些搜索,尽管我没有找到使用Tables集合的直接示例,但似乎支持此方法。

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 这只是一个改编自SqlServer上我的测试的示例,我没有进行Pervasive安装,但是如果结果相同,您可以尝试

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() 
         );
     } 
}

The psp_Columns system stored procedure is defined as call psp_columns(['database_qualifier'],'table_name', ['column_name']) . psp_Columns系统存储过程定义为调用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();

    }

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 对于可选参数,传入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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM