Reputation: 6432
I am getting an error when querying the value of an entry on another page, just after it is inserted into the database. The error is as follows:
Value cannot be null or an empty string.
Parameter name: commandText
The Stack Trace looks like this (not sure if this helps):
[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
The line the error occurs on (line 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:
I can't seem to find a reason for this error, as it occurs just after a user "saves" his/her entry into the database but occurrs sporatically and seemingly randomly. The page attempts to query the value of the unique primary key for that entry. The values stored within the session variables you see above were stored from the values previously just used to insert the new entry into the database (I have to do it this way because the primary key "is identity" and the value is automatically incremented with each entry addition).
There may be a better (simpler) way to do what I am trying to do, but I thought doing it this way would be more consistent than simply using MAX (aggregate function) on just the primary key.
There is probably more information I could give on this issue, but I really don't want to fill this page up with unnecessary information (if I haven't already). Just let me know if there is anything else I can provide.
A few more notes:
The 'Session["gDateLastModified"]' is grabbed from a field on the form that is automatically plotted using JavaScript, so this value (accurate down to the second) should (like all of the other variables in this query) match the values just entered into the database (Yes, I am sure that the user has JavaScript on and functioning correctly).
Also, it is probably obvious, but the QueryValue command on line 101 has the first argument as the select query string, using parameterized queries, of course, and the rest of the arguments are what must match to retrieve the row in the database.
Remember this error only occurs occasionally.
I am really sorry if I have added too much information (or left something out), but I don't know where to begin assuming what this problem might be, so not sure what all might help any who are trying to help me. Just let me know if there is anything else I can provide.
UPDATE
All I know for now is that a string is deliberately filled as long as it 'IsPost' then that string is used to directly fill the Session variable in question. I know that session variables are actually cookies, but being pretty certain that no one is manually clearing them (and they'd have to do that after hitting the submit button and before the next page loads, somewhere in the middle of this process), what else could cause this value to become cleared? I assume that commandText is a variable that is passed the value of my query string during db.QueryValue, is this correct?
Upvotes: 0
Views: 2014
Reputation: 251242
I would check that the session actually has the values before using them:
var activeEntrySelectQuery = (string) Session["activeEntrySelectQueryString"];
if (string.IsNullOrEmpty(activeEntrySelectQuery)) {
throw new ArgumentException("The active entry select query has gone missing.");
}
You could add appropriate additional information (and create your own type of exception) to help you find the issue. But I suspect this is the problem - the session doesn't contain the value you expect.
Upvotes: 1