문제

Porting MSSQL Application to Sybase (ASE 15.0), and experiencing a problem when I call GetDeleteCommand. The error reported is:

Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.

The problem only occurs for temporary table, identical non-temporary table works fine. Table contains a primary key.

Reproduced using test program below.



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.OleDb;
    using System.Data;

    namespace DataAdapterTempTable
    {
        class Program
        {
            static void Main(string[] args)
            {
                String ConnectionString = "Provider=ASEOLEDB;Data Source=devsun3:5003;Initial Catalog=ctc;User ID=aigtac12;Password=aigtac12;"; // sybase connection string
                //String ConnectionString = "Provider=SQLOLEDB;Data Source=fiji;Persist Security Info=False;Initial Catalog=nxgn0811;Integrated Security=SSPI"; // mssql connection string

                String TableName = "#alex_temporary_table_test"; // does not work for sybase
                //String TableName = "alex_real_table_test"; // works for sybase + mssql

                String CreateStatement = "create table " + TableName + " (currency_id varchar(4) primary key, rate  decimal(25,6), format   char(1))";

                String SelectStatement = "select * from " + TableName;

                try
                {
                    OleDbConnection con = null;
                    con = new OleDbConnection(ConnectionString);
                    con.Open();

                    OleDbCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = CreateStatement;
                    int count = cmd.ExecuteNonQuery();

                    OleDbCommand cm1 = con.CreateCommand();
                    cm1.CommandType = CommandType.Text;
                    cm1.CommandText = SelectStatement;
                    OleDbDataAdapter DA2 = new OleDbDataAdapter(cm1);
                    DataTable DT2 = new DataTable();
                    DA2.FillSchema(DT2, SchemaType.Mapped);
                    OleDbCommandBuilder cmdbldr = new OleDbCommandBuilder(DA2);
                    DA2.InsertCommand = cmdbldr.GetInsertCommand();

                    DA2.DeleteCommand = cmdbldr.GetDeleteCommand(); // this line fails in sybase for temporary table

                    DA2.UpdateCommand = cmdbldr.GetUpdateCommand();
                    DA2.Fill(DT2);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
    }


도움이 되었습니까?

해결책 2

Contacted Sybase support, turns out I had to update some system stored procedures. There is a folder that ends with "oledb\sp", and I had to run a .bat file from the folder. I got the latest ebf and ran the batch file install_oledb_sprocs.bat, the problem went away. Worth mentioning, that sybase 15.5 did not have the issue without patching.

P.S. Thank you to 'aF' for your time looking into the issue.

다른 팁

In the select statement, instead of * use the column names.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top