【问题标题】:Sybase BulkCopy WriteToServer error: Incorrect syntax near ','Sybase BulkCopy WriteToServer 错误:',' 附近的语法不正确
【发布时间】:2015-01-15 15:53:05
【问题描述】:

是否可以使用AseBulkCopy.WriteToServer 填充临时表?

我在我的测试应用程序中调用了以下方法两次:第一次使用非临时表,第二次使用临时表。代码在非临时表上运行良好,但在尝试填充临时表时出现错误:

Incorrect syntax near ','.

被提升了。

在这两种情况下,目标表和源表都只有一个列,定义为同名的 INT。

我尝试使用 DataTable 和 IDataReader 作为数据源,但都导致出现相同的错误。

我尝试在连接字符串中同时使用“EnableBulkLoad=1”和“EnableBulkLoad=2”。

我已尝试使用原始临时表名称和以“dbo”为前缀的名称。

要加载的数据是单个 int 值(即 1 行 1 列),尽管如果有更长的行或多行也会发生这种情况。

值得注意的是,我可以将数据插入到临时表中(使用 AseCommand.ExecuteNonQuery),并且可以成功地从临时表中执行“SELECT COUNT (1)”(使用 AseCommand.ExecuteScalar)。

代码如下:

  private static void BulkCopyInsertIntoTable(string tableName)
  {
    IDataReader dataSource = null;
    SqlConnection sourceConnection = null;
    MssqlCommand.GetDataReader(SqlServerConnectionString, out sourceConnection, out dataSource);
    AseConnection targetConnection = new AseConnection(SybaseConnectionString);
    try
    {
      targetConnection.Open();
      AseCommand cmd = new AseCommand();
      AseBulkCopy blk = new AseBulkCopy(targetConnection);
      blk.DestinationTableName = tableName;
      //blk.ColumnMappings.Clear();
      //blk.ColumnMappings.Add(new AseBulkCopyColumnMapping(0, 0));//Doesn't make any difference with a datasource, causes an error to be raised with a datatable.

      Console.WriteLine("bulkcopy insert into the table " + tableName + " ..starting: datasource");
      //blk.WriteToServer(dataSource);

      Console.WriteLine("bulkcopy insert into the table " + tableName + " ..starting: datatable");
      blk.ColumnMappings.Clear();
      DataTable dt = SybaseCommand.GetFakeDataTable(); ;
      blk.WriteToServer(dt);
    }
    catch (AseException ex)
    {
      Console.WriteLine(ex.Message);
    }
    finally
    {
      targetConnection.Dispose();
      Console.WriteLine("bulkcopy insert into the table " + tableName + " ..ended");
    }
  }

首先,是否可以使用WriteToServer 填充临时表? 假设是,我可能做错了什么?

更新: 当我换行时

blk.DestinationTableName = tableName;

blk.DestinationTableName = "XXXX";

我得到了同样的错误,那么在使用WriteToServer 时,有没有关于如何命名临时表的规则? tableName 的值是我用于直接INSERTSELECT COUNT(1) 查询的值,所以我希望它是正确的。

谢谢

【问题讨论】:

    标签: sybase sap-ase bcp


    【解决方案1】:

    根据我的经验,答案是否定的,您不能使用 AseBulkCopy.WriteToServer 来填充临时表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      相关资源
      最近更新 更多