【问题标题】:GetDeleteCommand DataAdapter with a temporary table in SybaseGetDeleteCommand DataAdapter 与 Sybase 中的临时表
【发布时间】:2012-01-10 22:14:34
【问题描述】:

将 MSSQL 应用程序移植到 Sybase (ASE 15.0),当我致电 GetDeleteCommand 时遇到问题。 报错是:

不支持为 DeleteCommand 生成动态 SQL 一个不返回任何键列信息的 SelectCommand。

这个问题只出现在临时表上,相同的非临时表可以正常工作。 表包含一个主键。

使用下面的测试程序复制。

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

【问题讨论】:

    标签: sap-ase dataadapter temporary


    【解决方案1】:

    在 select 语句中,使用列名代替 *

    【讨论】:

    • 但它确实有一个主键
    • 请尝试使用不同的#temporary 表名。以#alex 为例。
    • 尝试使用列名而不是*(在选择语句中)
    • 也尝试了列出列。我联系了 Sybase 支持,结果我不得不更新一些系统存储过程。有一个以“oledb\sp”结尾的文件夹,我必须从该文件夹中运行一个 .bat 文件。我得到了最新的 ebf 并运行了批处理文件 install_oledb_sprocs.bat,问题就消失了。值得一提的是,sybase 15.5 不打补丁就没有这个问题。
    【解决方案2】:

    联系了 Sybase 支持,结果我不得不更新一些系统存储过程。有一个以“oledb\sp”结尾的文件夹,我必须从该文件夹中运行一个 .bat 文件。我得到了最新的 ebf 并运行了批处理文件 install_oledb_sprocs.bat,问题就消失了。值得一提的是,sybase 15.5 不打补丁就没有这个问题。

    附:感谢“aF”花时间调查这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多