所以我在aaax调用一个预先输入文本框(bootstrap)时间歇性地收到此错误。重现很难,所以我没有取得多大进展。我怀疑它是由用户在输入中输入不会产生可发酵物的字符引起的。然后他们键入有效字符,第二个查询抛出此异常,尚未能证明这一点。有什么想法吗?
System.Data.SqlClient.SqlDataReader:172:in `get_MetaData'
System.Data.SqlClient.SqlDataReader:23:in `CheckMetaDataIsReady'
System.Data.SqlClient.SqlDataReader:8:in `GetName'
Dapper.SqlMapper+<>c__DisplayClass50:45:in `<GetDapperRowDeserializer>b__4f'
Dapper.SqlMapper+<QueryInternal>d__d`1:421:in `MoveNext'
System.Collections.Generic.List`1:119:in `.ctor'
System.Linq.Enumerable:20:in `ToList'
Brew.Controllers.RecipeFermentableController:46:in `GetFermentables'
方法:
[AllowAnonymous]
public JsonResult GetFermentables(string query)
{
try
{
using (var connection = ConnectionHelper.GetOpenConnection())
{
var fermentables = connection.Query(@"select top 10 Id, Name from Fermentables
where Name like '%'+@query+'%' order by Name", new {query});
return Json(fermentables.Select(s => new {s.Id, s.Name}), JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
e.SendToAirbrake();
throw;
}
}
GetOpenConnection内部:
var connectionString = ConfigurationManager.ConnectionStrings["BrewDb"].ToString();
var connection = new SqlConnection(connectionString);
connection.Open();
return new StackExchange.Profiling.Data.ProfiledDbConnection(connection,MiniProfiler.Current);