【发布时间】:2021-06-09 08:46:14
【问题描述】:
我试过这行代码,但遇到了错误
CMR cmr = _cmrServices.GetAllWithAll().Where(x => x.CMRSerial == cmrSearchDeliverySerialNumber).FirstOrDefault();
Inner Exception 1:
SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Inner Exception 2:
Win32Exception: The wait operation timed out
我无法在数据库中将字段的类型更改为整数,也无法将我的值与数字字符串进行比较,因为它会出现超时错误。
cmrSearchDeliverySerialNumber 这个字段虽然是字符串,但无论它是什么类型,我都无法将CMRSerial 字段过滤为整数。
我不知道应该使用 SqlFunctions.StringConvert 还是其他东西来将 CMRSerial` 转换为整数。
很遗憾,我无法在 CMRSerial 字段上设置索引,因为它的类型是 nvarchar(max),我无法将它作为字符串与另一个字符串进行比较。
我在执行探查器创建的查询后运行了这行代码
SELECT QP.query_plan as [Query Plan],
ST.text AS [Query Text]
FROM sys.dm_exec_requests AS R
CROSS APPLY sys.dm_exec_query_plan(R.plan_handle) AS QP
CROSS APPLY sys.dm_exec_sql_text(R.plan_handle) ST;
【问题讨论】:
-
在CMRSerial上放一个索引
-
@JamesBlackburn 我的问题不是超时。它正在转换
-
你正在做一个隐式转换,这在性能方面真的很糟糕。我会建议做一个明确的转换/转换,然后comapre它。根据经验,如果它看起来像整数但不是,并且您想比较它,请先转换它(但要告别该列上的任何索引)
-
@GertArnold 我刚刚问了关于在 linq 中将字符串字段转换为整数的问题。