我在从 Sybase API 中的 AseCommand 对象运行 Sybase SQL 脚本时遇到问题。这是我的脚本的副本,它作为 sql 字符串参数传递到 C#
SQL 脚本:
DECLARE @dt DATETIME
DECLARE @mx INT
SELECT @dt = getDate()
EXEC DATABASE_NAME..StoredProcedure1
@id_own_grd = 200,
@id_dom_grd = 'TEST VALUE',
@value = @mx OUTPUT
EXEC DATABASE_NAME..StoredProcedure2
@id_level = @mx, @id_level_pt=NULL, @id_obj1 = 58464819,
@id_typ_lvl='TEST', @am_test=20130916, @id_obj1_sub = 12949,
@dt_start_lvl = '9/16/2013', @dt_end_lvl = '9/16/2013',@ct_blah=0,
@id_abs=" ", @id_obj1_trans=0,@am_obj1_vol=NULL, @am_obj3=-0.311095,
@id_obj_test = NULL, @id_obj5_test = NULL, @id_is_valid = '0',
@nm_db_origin='ORIGIN_DB', @id_owner=200
调用上述 SQL 脚本的 C# 代码:
public Dictionary<int, Dictionary<string, object>> ExecuteSqlQuery(string sql)
{
lock (this)
{
try
{
using (AseCommand command = new AseCommand(sql, Connection))
using (AseDataReader reader = command.ExecuteReader())
{
Log.Info("Executing Query: [" + sql + "] on " + DbSettings);
command.CommandTimeout = 120;
var results = new Dictionary<int, Dictionary<string, object>>();
var columns = new List<string>();
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
}
int row = 0;
while (reader.Read())
{
Dictionary<string, object> rowResults = new Dictionary<string, object>();
results.Add(row, rowResults);
foreach (string item in columns)
{
rowResults.Add(item, reader[item]);
}
row++;
}
Log.Info("Finished Executing Query: [" + sql + "] on " + DbSettings + " in " + timer.TimeTaken());
return results;
}
}
catch (Exception e)
{
Log.Error("An error occured executing query SQL: " + e.Message, e);
throw;
}
}
}
每当我尝试运行上述脚本时,都会抛出并捕获一个 Sybase.Data.AseClient.AseException,上面写着“参数数量无效”。此 C# 代码适用于不调用存储过程的任何其他代码。我知道 Sybase 有调用存储过程的特定步骤,尤其是输出参数,详见此链接:
但是,我的用户希望能够在一个脚本中调用多个存储过程——我还不知道该怎么做。有人有什么想法吗?
谢谢,