• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem: variable disappears from Session after <cfquery>

New Here ,
Jul 06, 2007 Jul 06, 2007

Copy link to clipboard

Copied

I have the following problem in my CFML script. I added a variable MyVariable in Session variable. Then I call <cfquery>. When the <cfquery> finishes, the variable MyVariable does not exist in the Session!



Views

904

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2007 Jul 06, 2007

Copy link to clipboard

Copied

How exactly is it that you set the variable? How is it that you discover that it's no longer there?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

In fact, name of the MyVariable was loginresult. The sequence was approximately as the following:


<cfset Session["loginresult"] = 0>
...
<cfif Session["loginresult"] eq 0>
<cfquery ...>
<cfif Session["loginresult"] eq 0>
...
</cfif>
</cfquery>

</cfif>

The problem happened on SECOND line "<cfif Session["loginresult"] eq 0>" - one that follows <cfquery>. The line produces exception :

coldfusion.runtime.UndefinedElementException: Element loginresult is undefined in a Java object of type class coldfusion.runtime.MemorySessionScope referenced as


What is most misterious, I have teh same CFM code on two computers (ColdFusion MX7 on both). One of them the code works OK; on other it causes the problem I described.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

> <cfif Session["loginresult"] eq 0>
> <cfquery ...>
> <cfif Session["loginresult"] eq 0>

My question is... why are you even DOING the second <CFIF>? One can only
possibly get to that code on the basis of that expression already being
true.

If you're concerned about race conditions, you should be locking the code.
In which case you really oughtn't being doing the query inside the lock
anyhow, if it's possible to avoid.

Perhaps it might help working out what's going on if you post a bit more
code... all the code between the <cfset> and the bottom of the outer
<cfif>.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

Yes, odd. Do you use cflock anywhere? What happens when do it like this

<cfset request.loginresult = Session["loginresult"]>
<cfquery ...>
<cfif request.loginresult eq 0>
...
</cfif>
</cfquery>


edited: stray 'eq 0' removed

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

What happens if you try to dump the session structure immediately before and after your query?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

I did the dump. Content of the object Session seems did not change except the variable loginresult - it has gone. Values of Session.CFID, Session.CFToken, Session.URLToken, Session.SessionID did NOT change.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

It's not a code problem. Since the code works on one machine and not the other, look for differences in cf, webserver, operating system, etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2007 Jul 07, 2007

Copy link to clipboard

Copied

I don't normally like lots of code to view thru, but could you add more of the code to your question.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 08, 2007 Jul 08, 2007

Copy link to clipboard

Copied

Did you switch to request scope as I suggested? What happened?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied

Thank you for the help. I have found the reason - that was multi-threading. As it tuned out, TWO threads simulatneously used my CFM module. The module has deleteion of the "loginresult" variable in its begin. So second thread deleted the variable first thread had created before.

To fix the problem I used <cflock>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2007 Jul 09, 2007

Copy link to clipboard

Copied

LATEST
> that was multi-threading
One could guess as much.

> To fix the problem I used <cflock>
Not a good idea. The database exercises its own lock, beyond Coldfusion's control. You should therefore avoid using cflock within a query.

Besides, a lock might not even be necessary. If you must, then use something similar to the strategy I gave above, namely,

<cflock type="readOnly">
<cfset request.loginresult = Session["loginresult"]>
</cflock>
<cfquery ...>
<cfif request.loginresult eq 0>
</cfif>
</cfquery>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation