Tech Blog

Jay's Technical blog

Some new personal projects

28 July 2004
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

Soon, I will be playing with Mono on Mac OS X.  I plan on porting an app that I built in JSP to ASP.Net (with C#).  Then I can farm all the support work to Dave <grin>.  I'm so excited about this you can't even imagine. 

That coupled with me being able to join the QueryCommander Project in the GotDotNet Workspaces... Query Analyzer with intellisense! 

Oh yeah, and I'm in the process of installing the new beta of SQL Express (Oh my!  I've joined the ranks of futuritis! Can it be?!?!!)

I close on my new house in less than 2 weeks, so hopefully I can find time to continue blogging.

Dot Net Q&amp;A

26 July 2004
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

I had Donny create the .Net Q&A blog.  I haven't had a bunch of questions.  I've been thinking about going into the dreaded newsgroups and posting a bunch of questions from there that I can answer (or that I think others can answer) to try to “jump start” the blog.  (BTW, I checked the logs today and both Google and MSN are indexing it fairly well considering that we have a grand total of 3 questions - 2 of which are mine).

What do you guys think?

Something strange I'm trying to accomplish...

26 July 2004
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

I have something weird I'm trying to accomplish and was wondering if anyone has tried/accomplished this.

Here's the problem (briefly).

I have some power users of a system that I built that use MS Access as a frontend to SQL Server.  They have direct table access.  I want to wean them off of this, and would preferably like to give them some stored procs... unfortunately they have some mini apps in MS Access against the data.  Beyond me teaching them how to call SQL server via the Jet engine (creating a connection to SQL through a connection/recordset object) is there any way I can hook a .Net assembly into Access that would let me display some dummy tables (or dummy queries) that when called will invoke methods in my .Net assembly (BTW, this is MS Access 2003).

I've been looking through the mess that is MS Access and can't seem to make heads or tails of how I can do this (or even if it is possible).

I'm going to Q&A this one...

Some fun with my mistake...

26 July 2004
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

Ok, as previously stated I rushed out my last post.  I had a bug in my code that resulted in a subtle problem. 

Just out of curiosity, raise your hand if you tried to use my code (ok, put it down again... I can't really see you, but people around you can, and they're staring).

Let see how many hands was that?? None I bet.  If you had , you would discover that... it doesn't work!  There is a more heinous error in the code than previously stated.

Let's recap.  I give you 4 routines.  Each of the routines let's you pass a key in and it handles the adding of the session id to the key to get a value out of the application cache.  Did anyone notice that in the “writeVarToContext” I have this line of code in it “removeKeyFromContext(key + Session.SessionID).”  Does this code strike anyone as odd? 

Wait, I have it!  Doesn't the removeKeyFromContext routine already handle the concat'ing of the Session ID?  So you add it to the key twice?  Wouldn't this cause an error? 

Yep, it sure does... editing the post again (sigh)

BTW, I like to make sure that everyone knows that I'm not infallible (hence the reason for this post). 

ASP.Net: Transfering data between pages.

24 July 2004
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

[I hope that I don't drive my readers crazy.  I'd love to settle on 1 topic and become an expert in that oen topic.  I just have way too many interests right now]

As I have coded web apps (in both ASP and ASP.Net as well as JSP) over the last 6 or 7 years (wow, it's been that long), I have had a recurring problem.  How do I transfer data between pages?

Initially my answer was what a lot of us do.  I simply put the data in the QueryString.  It's very easy and you can easily retrieve it.  The only problem of course (that I discovered through someone else's err) is that power users quickly realize that by messing with values in the querystring they can get the page to potentially do different things (especially if you've forgotten to add necessary checks).  This post here on The Daily WTF. Needless to say be cautious of QueryStrings and if you can avoid them then definitely avoid them.

After realizing what kinds of problems can happen I chose a different route.  I build a small form with nothing but hidden fields and I post the form to the new page (usually through a javascript).  The values are hidden in the form, so this seems like a good solution, but hold on... This is a good solution but it is definitely not a secure one.  Form posts can be spoofed (it's never happened to me, but I've become aware of the fact that form posts have issues.

So now what can we do?  I've heard people mention session. But cluttering session just sounds like a bad idea to me. 

The answer that I have come up with is the app cache.  It's perfect.  Data never touches the client's machine.  The only piece of information that the client touches is the the session id (which I combine with a “ket“ to create the cache's key).  Cache can be set to timeout, so you're not waiting until session times out -- you can safely time out the information sooner because it is only for a page transfer.  The only place this wouldn't work is if you're in a multi-server environment and you're not using sticky sessions.

Anyway, here's the code I wrote for this (it handles the adding of the Session ID to yor keys) [edited the code because Dave --a different one than the one I normally write about-- pointed out that I forgot the type on the first constant which is absolutely necessary]:

' Timeout for data being transfered is 2 minutes

' Remove a key from the transfer cache

    context.Cache.Remove(key + Session.SessionID) 

' Check if a particular key exists in the transfer cache
   Return(Not(context.Cache(key + Session.SessionID)IsNothing)AndAlso_
CStr(context.Cache(key + Session.SessionID))) > 0)

' Reads a key back from the transfer cache
     Dim__InContextAsBoolean= existsInContext(key)
     If__InContext =FalseThenReturn""
      ' [ As my mom says “Some days I do better than others.. some more bad code,
      '   but I think this is the last of it]
      '  Context.Items.Add(key, _
      '         Server.UrlEncode(
CStr(context.Cache(key + Session.SessionID).ToString))) 

     ReturnServer.UrlDecode(Context.Cache(key + Session.SessionID).ToString)  

' Writes data with a key to the Transfer Cache
   IfexistsInContext(key)ThenremoveKeyFromContext(key)' [fixed this line of code]
    context.Cache.Add(key + Session.SessionID, _
Nothing,Date.MaxValue, _
                      System.TimeSpan.FromMinutes(PAGE_XFER_CACHE_TIMEOUT_IN_MINUTES), _


There you go.  Let me know what you guys think.