Multiuser Approach, how to?

  • Thread starter Thread starter Christian Pické
  • Start date Start date
C

Christian Pické

Hi,

I am building a Windows Application (Three Tier, SQL-server, Stored
Procedures).

What is the best apraoch for a multiuser application? Just catching an SQL
update error and retry a couple of times? And what about ID's based on SQL
identities? I guess you cannot avoid doubles when using this technique in a
disconnected environment?

All ideas or references are welcome!
 
Hi Christian,

Christian Pické said:
Hi,

I am building a Windows Application (Three Tier, SQL-server, Stored
Procedures).

What is the best apraoch for a multiuser application? Just catching an SQL
update error and retry a couple of times?

Are you talking about concurrency?
Check
Concurrency Control in ADO.NET .net help topic.

And what about ID's based on SQL
identities? I guess you cannot avoid doubles when using this technique in a
disconnected environment?

It is not a problem. While they are disconnected the new ones should be
negative (just to distinguish them). Once the dataset is updated to database
dataadapters should retrieve and update identities with actual values.

There is a help topic:
Retrieving Identity or Autonumber Values
 
Christian Pické said:
Hi,

I am building a Windows Application (Three Tier, SQL-server, Stored
Procedures).

What is the best apraoch for a multiuser application? Just catching an SQL
update error and retry a couple of times?

In case of a concurrency error, you have to make a decision.

Either:
1) Ignore it and overwrite the other user's changes.
2) Throw away your changes, get the current data, and make the user
re-enter the transaction.

Also you can be proactive and prevent other users from updating the records
you are looking at. This is called pessimistic concurrency, and you do this
by doing your select's inside transactions and holding your shared read
locks until the user has closed the form. This can be tricky with
SQLServer, as it's easy to mess up your concurrency, and it kind of goes
against the grain of the disconnected model, but it can be done.
And what about ID's based on SQL identities? I guess you cannot avoid
doubles when using this technique in a disconnected environment?

Sure you can. The basic idea is to user DataTables with AutoIncrement
columns, set the seed and increment to -1. So New rows get -1,-2,-3, etc.

Then when you do the insert, SQLServer assigns its own id's, and you update
your temporary ID with the one assigned by the server. Here are a couple of
links outlining the technique.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/manidcrisis.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;310350
 
Back
Top