Sybase ASE BulkCopy "The data type or the function is not supported" 写入非空用户定义类型

Sybase ASE BulkCopy "The data type or the function is not supported" writing to a non-null user-defined type

我在将 NUMERIC(8,0) 从 Sql 服务器迁移到 ASE (v16.0) 中具有用户定义类型 NUMERIC(8,0) 的列时遇到问题。

我有简单的用户定义类型:

IF EXISTS (SELECT * FROM systypes WHERE name='typ_small_id')
BEGIN
EXEC sp_droptype 'typ_small_id'
IF EXISTS (SELECT * FROM systypes WHERE name='typ_small_id')
    PRINT '<<< FAILED DROPPING DATATYPE typ_small_id >>>'
ELSE
    PRINT '<<< DROPPED DATATYPE typ_small_id >>>'
END
go
EXEC sp_addtype 'typ_small_id','numeric(8,0)','NOT NULL'
go
IF EXISTS (SELECT * FROM systypes WHERE name='typ_small_id')
    PRINT '<<< CREATED DATATYPE typ_small_id >>>'
ELSE
    PRINT '<<< FAILED CREATING DATATYPE typ_small_id >>>'
go

这个用在小table:

create TABLE dbo.target
(
    e_type_id     typ_small_id  /*NOT*/ NULL
)

我正在尝试使用 AseBulkCopy.WriteToServer 从 Sql 服务器批量复制单个值。源值在 SqlServer 中定义为 NUMERIC(8,0)。 我正在使用 ASE 的 .net 客户端,我的应用程序代码是 C# :

public void BulkCopyFromSqlServer_t_sec_exchange(string sourceConnectionString, string targetConnectionString) { SqlConnection sourceConnection = null; AseConnection targetConnection = new AseConnection(targetConnectionString); try { IDataReader dataSource; //The next method call returns a single row with a single column, defined as a NUMERIC (8,0) in SqlSvr. MssqlReader.GetDataReaderSelect_t_sec_exchange(out sourceConnection, out dataSource); targetConnection.Open(); AseBulkCopy blk = new AseBulkCopy(targetConnection, new AseBulkCopyOptions(), null); blk.BulkCopyTimeout = 1200; blk.DestinationTableName = "dbo.target"; blk.ColumnMappings.Clear(); blk.WriteToServer(dataSource); blk.Close(); } catch (AseException ex) { Console.WriteLine(ex.Message); } finally { sourceConnection.Dispose(); targetConnection.Dispose(); } }

来自Sql服务器的值为 1。 这一切都很好,直到我将 target.e_type_id 定义为 typ_small_id NOT NULL 而不是可为空。 当我这样做时,我得到一个 AseError: The data type or the function is not supported.

堆栈跟踪: at Sybase.Data.AseClient.AseBulkCopyBusinessBulk.TdsToAseDBType(TdsTypesDefines type, Int32 len, Int32 usertype, Boolean IsNullable, Int32& DateTimeLen) at Sybase.Data.AseClient.AseBulkCopyBusinessBulk.InitMetadata() at Sybase.Data.AseClient.AseBulkCopyBusinessBulk.InitFmtData() at Sybase.Data.AseClient.AseBulkCopyBusinessBulk.BulkOperation() at Sybase.Data.AseClient.AseBulkCopyBusinessBulk.RunInsertsRowsReader() at Sybase.Data.AseClient.AseBulkCopy.WriteToServer(IDataReader reader) at SybaseBulkCopy.SybaseCommand.BulkCopyFromSqlServer(String sourceConnectionString, String targetConnectionString) in c:..\SybaseCommand.cs:line 32

当列定义为 typ_small_id NOT NULL 时,以下查询都成功地将数据从查询编辑器插入到列中,因此看起来像是 WriteToServer 代码中的错误:

insert into dbo.target ( e_type_id ) SELECT top 1 cast(1 as numeric(8,0)) as e_type_id from source_tbl

insert into dbo.target ( e_type_id ) SELECT top 1 cast(1 as int) as e_type_id from source_tbl

不用说,客户的 table 列定义为非空(并且不能更改模式),所以我需要了解如何将数据迁移到他们的 ASE table。

有没有人看到这个或找到解决方法?

这已被 SAP(Sybase 技术支持)确认为错误。