2015-01-15 37 views
0

是否可以使用AseBulkCopy.WriteToServer填充臨時表?Sybase BulkCopy WriteToServer錯誤:「,'附近的語法不正確

我在我的測試應用程序中調用了下面的方法兩次:第一次使用非臨時表,第二次使用臨時表。該代碼運行正常與非臨時表,而是試圖填充一個臨時表中的錯誤時:

Incorrect syntax near ','.

提高。

在這兩種情況下,目標表和源表都只有一列,被定義爲具有相同名稱的INT。

我已經嘗試使用DataTable和IDataReader作爲數據的來源,並且都導致提出相同的錯誤。

我已經嘗試在連接字符串中同時使用「EnableBulkLoad = 1」和「EnableBulkLoad = 2」。

我曾嘗試使用原始臨時表名稱和帶有「dbo」前綴的名稱。

要加載的數據是一個單一的int值(即1行1列),儘管如果有更長的行或多行也會發生這種情況。

值得注意的是,我可以將數據插入臨時表(使用AseCommand.ExecuteNonQuery),並且可以從臨時表(使用AseCommand.ExecuteScalar)成功執行'SELECT COUNT(1)'。

下面是代碼:

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臨時表? 假設是這樣,我可能會做錯什麼?

UPDATE: 當我改變行

blk.DestinationTableName = tableName; 

blk.DestinationTableName = "XXXX"; 

我得到了同樣的錯誤,那麼,有沒有規則,規定臨時表是如何使用WriteToServer時命名? tableName的值是我用於查詢的直接INSERTSELECT COUNT(1),所以我預計它是正確的。

感謝

回答

0

以我的經驗,答案是否定的,你不能使用AseBulkCopy.WriteToServer到一個臨時表。

相關問題