2014-03-04 80 views
1

當執行與用於設置局部變量多於一個參數的查詢,我得到這個錯誤:Sybase與多套「沒有足夠的值,主機變量」

iAnywhere.Data.SQLAnywhere.SAException (0x80004005): Not enough values for host variables

我使用兩種OdbcConnection得到同樣的錯誤或SAConnection。

DECLARE @A int 
DECLARE @B int 
SET @A = ? 
SET @B = 42 

我在任何地方的Sybase服務器12.0.1.3942運行此:

var connection = new SAConnection(connectionString); 
connection.Open(); 
var transaction = connection.BeginTransaction(); 

string sql = @" 
DECLARE @A int 
DECLARE @B int 
SET @A = ? 
SET @B = ? 
"; 

var command = new SACommand(sql, connection, transaction); 

var param1 = new SAParameter(); 
param1.Value = 1; 
command.Parameters.Add(param1); 

var param2 = new SAParameter(); 
param2.Value = 2; 
command.Parameters.Add(param2); 

command.ExecuteNonQuery(); 

查詢,如果只有一個參數執行罰款。

更新:經過更多測試後,我發現它發生在同一查詢中有多個參數化語句時。這也給了錯誤:

SELECT ? 
SELECT ? 

回答

3

有明顯some obnoxious restrictions在SA數據庫引擎:

Host variable references are permitted within batches with the following restrictions:

  • only one statement in the batch can refer to host variables
  • the statement which uses host variables cannot be preceded by a statement which returns a result set

一個解決辦法可能是選擇荷蘭國際集團所有的主機變量(參數)地方變量之前使用它們:

BEGIN 
    DECLARE @id INT; 
    DECLARE @name NVARCHAR; 
    DECLARE @comment NCARCHAR; 
    SELECT :id, :name, :comment INTO @id, @name, @comment; 
END; 
相關問題