This topic is locked
[SOLVED]

 Bogus "Invalid column name" exception

9/13/2016 1:26:59 PM
ASPRunner.NET General questions
Pete K author

I have a table "Enrollment" that contains a field "Learner" of type varchar. I had applied an additional where clause by inserting the following code in the table AfterTableInit() event:



// Show only enrollment for this user
string thisUser = XSession.Session["UserGUID"];

string wc = " Learner = '" + thisUser + "' ";

query.addWhere(wc);


It was working -- then suddenly it was not. When I view [size="2"]Enrollment/list, I get a YSOD with the error: [/size]Invalid column name 'Learner'.
The field is still there; if I comment out the last line of code, the page loads normally and the Learner column is there as expected. I spent a lot of time syncing and re-syncing the database, exiting and opening ASPRunner, doing full builds, everything I could think of. Then as an experiment, I tried filtering on another field in the same table. Then it got weirder:
[size="2"]


// Show only enrollment for this user
string thisUser = XSession.Session["UserGUID"];

//string wc = " Learner = '" + thisUser + "' ";

string wc = " Status = 'R' ";

query.addWhere(wc);


Resulted in: Conversion failed when converting the varchar value 'R' to data type tinyint.
But the status field is (and always has been) a single character, not a tinyint (or a varchar). [/size]
[size="2"]Running a SQL Profiler trace on the first example, I can see that the query actually got passed to SQL and the data was retrieved: [/size]
[size="2"]



SELECT

[EnrolID], [Offering], [Learner], [EnrolDate], [Status]

FROM [dbo].[Enrollment] where (((( Learner = '20160909pkoutoul' )))) ORDER BY 1 ASC

[/size]
[size="2"]You can see by the screenshot I attached, ASPR has all of this right in the database design (Tables) section. To me it seems as if the DAL code is not in sync with the stored properties as recognized by the IDE. Is this is bug? I'm using the 27012 x64 build of version 9.0.
[/size]

Pete K author 9/13/2016

Okay, I finally solved this -- sort of. I just deleted the table from the project, did a rebuild, then added it back. And it's working -- for now. But I would really like to know why this happened and if there is a less destructive fix. It just so happens that I am early in the project and had made no modifications other than the code snippet so it was relatively painless. But it could have been a nightmare.

Pete K author 9/13/2016

Not solved after all and it's definitely a bug. I'm submitting a ticket. It occurs when there is a field that contains a lookup wizard in the same table being filtered with the additional where clause.

Sergey Kornilov admin 9/13/2016

Yes, please submit a ticket. Need to see what's happening there.

Pete K author 9/15/2016

I submitted a ticket; it was indeed a bug and Alexey issued a patch which has solved the issue for me. I assume the fix will be included in future builds.