【发布时间】:2012-12-10 14:33:23
【问题描述】:
我在查询另一个页面上的条目值时遇到错误,就在它被插入数据库之后。错误如下:
Value cannot be null or an empty string.
Parameter name: commandText
堆栈跟踪如下所示(不确定是否有帮助):
[ArgumentException: Value cannot be null or an empty string.
Parameter name: commandText]
WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +20791
ASP._Page_EntryViewer_cshtml.Execute() in c:\Users\administrator.OKMCITY\Documents\My Web Sites\Persons Of Interest\EntryViewer.cshtml:101
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +62
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
发生错误的行(第 101 行):
Line 99: var db = Database.Open("PersonsOfInterest");
Line 100:
Line 101: var activeID = db.QueryValue((string)Session["activeEntrySelectQueryString"], (string)Session["gPOIName"], (string)Session["gDateLastModified"], (string)Session["gGender"], (string)Session["gRace"], (string)Session["gHeight"], (string)Session["gWeight"], (string)Session["gHairColor"], (string)Session["gEyeColor"], (string)Session["gDOB"], (string)Session["gAge"], (string)Session["gSS"], (string)Session["gDL"], (string)Session["gDOC"], (string)Session["gVehicleTag"], (string)Session["gFBI"], (string)Session["gOfficer"], (string)Session["gAdditionalDescriptors"], (string)Session["gHomePhone"], (string)Session["gAliases"], (string)Session["gSourceOfInformation"], (string)Session["gAddress"], (string)Session["gAddressInformation"], (string)Session["gKnownAssociates"], (string)Session["gVehicleDescription"], (string)Session["gCellPhone"], (string)Session["gCellPhone2"], (string)Session["gCellPhone3"], (string)Session["gPOICautions"], (string)Session["gComments"], (string)Session["gWorkPhone"], (string)Session["gSummarizedIncidents"], (string)Session["gPOILastName"]);
Line 102: Session["gEntryID"] = activeID;
Line 103:
我似乎找不到这个错误的原因,因为它发生在用户“保存”他/她进入数据库之后,但偶尔发生并且看似随机。该页面尝试查询该条目的唯一主键的值。您在上面看到的会话变量中存储的值是从以前刚刚用于将新条目插入数据库的值存储的(我必须这样做,因为主键“是身份”并且值会随着每个条目添加)。
可能有更好(更简单)的方法来做我想做的事情,但我认为这样做比仅在主键上使用 MAX(聚合函数)更加一致。
关于这个问题,我可能可以提供更多信息,但我真的不想用不必要的信息填满这个页面(如果我还没有的话)。如果还有什么我可以提供的,请告诉我。
还有几点说明:
'Session["gDateLastModified"]' 是从使用 JavaScript 自动绘制的表单上的字段中获取的,因此该值(精确到秒)应该(与此查询中的所有其他变量一样)匹配刚刚输入数据库的值(是的,我确信用户已打开 JavaScript 并正常运行)。
另外,这可能很明显,但是第 101 行的 QueryValue 命令将第一个参数作为选择查询字符串,当然使用参数化查询,其余参数是检索行中的行所必须匹配的数据库。
记住这个错误只是偶尔发生。
如果我添加了太多信息(或遗漏了一些信息),我真的很抱歉,但我不知道从哪里开始假设这个问题可能是什么,所以不确定所有这些都可能对任何试图提供帮助的人有所帮助我。如果还有什么我可以提供的,请告诉我。
更新
我现在所知道的是,只要它是“IsPost”,就会故意填充一个字符串,然后该字符串用于直接填充有问题的 Session 变量。我知道会话变量实际上是 cookie,但可以肯定没有人手动清除它们(他们必须在点击提交按钮后和加载下一页之前,在这个过程的中间某个地方这样做),还有什么可能导致该值被清除?我假设 commandText 是一个变量,它在 db.QueryValue 期间传递了我的查询字符串的值,这是正确的吗?
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# sql sql-server-ce webmatrix