Showing posts with label boy. Show all posts
Showing posts with label boy. Show all posts

Sunday, February 12, 2012

Boy am in big trouble!

I just got finished developing the company intranet site and thinking that everything was working I boasted about how good it was by getting my boss to login and submit a new job to the db (new job, its a work management app) while i did the same, the pland was to hit the submit button at the same time. He would send one to be read by me and I would send one to be read by him. We both hit submit and the following happened.

The db has somehow fused the two into one. I thought maybe we were to accurate in hitting the submit button together. But I even gave a five second delay between and for some reason the job is being overriden by one user tor the other. In other words we are both sharing the same jobid. I thought this could never happen with sql server supposing that it would lock one request until another was completed and vice versa. But I'm so new to this that I'm just so naieve to think that the db would do this for you. Problem is I'm about to move on and I can't leave the app in this state. Can anyone point to some articles or give some suggestions has to my situation. Most desperately in need!!

Thanks in advanceoh crap. that's insane man. what's the db architecture, and are you using procedures to do the transactions? need more info. it shouldn't allow multiple inserts to be merged into one unless you're using a datatable to hold the data, and you're doing that incorrectly.|||In fact, if you want, just aim me in the morning. PST, and I'll help you out then, and post the logs here.|||I use stored procedures and transactions.

Where do i get the logs?|||Nevermind. Actually.. I can't see how this is happening.

In fact, it's impossible unless you're creating the primary key manually, or trying to do something uncommonly complicated, and messed up along the way.|||This is what I'm doing and It makes sense why it doing this but I'm not sure of a solution.

Let me explain.

I have two processes.

I add a job to my db, the job contains a title, date, time etc.

When the user submits it they are returned a job number from the db. They then need to add a note that goes along with the job. This job is stored in a job table

A job can have many notes but they must add at least one, thats the default behaviour. When having submitted the note the details are stored in a note table, its foreign key is the jobid that was returned from the first insert.

IE I can access all the notes by its jobid.

The problem occurs when two people do this

User A : Adds a job

User B : Adds a job

I think user a's jobid is being written over by user b. Therefore when (user a) add a note they are actually submitting the note to the jobid of user b.

Now thats my hunch. And it certainly explains the behaviour. Problem is that I can't really afford to change the structure of the entire thing right now. What would really help is if I was able to prevent (user a's) job number from being over written. I'm using static vars.

Any suggestions would be most helpful!!|||dont you have a username/userid column tht you can use to differentiate among users ?|||I'm going to go on a limb, and assume the JobID foriegn key is an int - Identity with an increment seed of 1 right?|||I found the problem and it had nothing to do with my db. I was using a property to store my jobid, which meant that the last person to add a new job would be overwritting the previous persons job id. If user a had'nt submitted is note before user b added a new job the user a's job id would be overwritten by users b's. So user a would be submitting a note with a foreign keys from user b.

Now I know what going on I am kinda on the road to recovery.

I just need to figure out what kind of variable I can use to persist a jobid across different users so they don't overwrite one another. I'm thinking session variables. But I'm so new at this I'm not sure if theres a better way?|||property? you aren't creating a new instance of the object, and sharing it between multiple calls? That's a bit unstable don't you think?|||Sometimes we learn those hard lessons through trial and error.|||I hear ya. :) I've done the same before actually.

this is OT, but hope it makes you feel better... two nights ago, I made a while loop with three nested loops and two methods. Two of the methods work with each other to determine the end of the loop. Let's just say I forgot to set the condition to false. :) Saw my ram go straight to 2gigs of usage from a single process.

And yeah, I've done some pretty interesting things that when looking back now.. I scoff at myself, but you're right, it's a live and learn ordeal.

Good luck in finishing.