我在将NUMERIC(8,0)
从Sql Server迁移到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
这用于小表:
create TABLE dbo.target
(
e_type_id typ_small_id /*NOT*/ NULL
)
我正在尝试使用AseBulkCopy.WriteToServer
从SqlServer BulkCopy一个值。源值在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();
}
}
来自SqlServer的值为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
毋庸置疑,客户的表将列定义为非空(并且不能更改架构),因此我需要了解如何将数据迁移到其ASE表中。
有没有人看过这个或找到了解决方法?
答案 0 :(得分:0)
这已被SAP(Sybase技术支持部门)确认为一个错误。