我有一个非常奇怪的问题。我有一个存储过程,其中包含以下参数:
@Id int OUTPUT,
@DataSourceId int,
@OwnerId int,
@Size numeric(16,6),
@SizeUnitId int,
@LayCanFrom datetime,
@LayCanTo datetime,
@DischargeDate datetime,
@IMO int,
@ProductIds inttable readonly,
@LoadPortIds inttable readonly,
@DischargePortIds inttable readonly,
@LoadCountryIds inttable readonly,
@DischargeCountryIds inttable readonly,
@LoadZoneIds inttable readonly,
@DischargeZoneIds inttable readonly,
@FreightRate numeric(16,6),
@FreightRateUnitId int,
@StateId int,
@OriginalMessage varchar(max),
@Comments varchar(max) = null
这里感兴趣的特殊参数是@Size数字(16,6)。 在C#方面,当我调用存储过程时,我将该参数声明为:
var paramSize = command.Parameters.AddParameter("@Size", this.Size);
paramSize .SqlDbType = SqlDbType.Decimal;
paramSize .Size = 16;
paramSize .Precision = 6;
我得到的连接字符串为:
using (var connection = new SqlConnection(
(context.Connection as EntityConnection).StoreConnection.ConnectionString))
{
// Call function to execute the stored proc.
}
然后我打开连接,并执行通常的command.ExecuteNonQuery();
现在@Size传入75000.000000,这应该没问题,因为该字段是数字(16,6)。实际上,我已经在同一个表中有记录,其大小列中的值为75000.000000。但是,当我拨打command.ExecuteNonQuery();
时,它会以
参数值' 75000.000000'超出范围。
因此,我决定将存储过程中的@Size默认为75000.000000,而不是传递参数。你猜怎么着?有用!另一个有趣的问题是我正在尝试使用SQL事件探查器捕获SP执行,无论我尝试什么,或者我选择捕获哪些事件,我都无法看到SP执行。这是因为我从EF storeconnection获取连接字符串吗?以前有人遇到过这样的事吗?这让我有点疯狂! :)