Must we use a disconnected model when creating database applications?

Lenny Gray
Lenny Gray used Ask the Experts™
I am new to Is it mandatory that we use a disconnected model when using Sql Server?

Can we use a persistent connection to a Sql Server database like the old OpenDatabase command?

I am uncomfortable with the disconnected model because I do not understand it well. For instance: Table #1 is loaded into an application as disconnected. A user of that application makes changes to Record #15. But, in a parallel session, Record #15 in Table #1 is changed by another user in another application that is accessing that database too. Let's assume that the last name is changed in both

How is the record's data resolved?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Connected or not, you will have exactly the same issue. When you retrieve data from the database, updates made by other users are not automatically sent to those already having a copy.

You need to implement some mechanism like a time stamp to prevent updating what others might have done.


I agree. And thanks for the response. The mechanism that I'd favor is record level locking. I would not expect more than ten multiple concurrent users.

What is the proper syntax for keeping a connection to SqlServer database?  What do i use in place of the dataAdapter.fill command after I open the connection?

it is my understanding that after the fill command, the data connection closes.

How do I invoke record locking?

Éric MoreauSenior .Net Consultant
Top Expert 2016

there is no such as an live connection in ADO.Net. It is not the way to go!

In your table, add an integer field and call it TimeStamp for example. When you read the values, be sure that this field is also read.

When you update the values, add "SET TimeStamp = TimeStamp + 1 WHERE TimeStamp = thevalueyouread". this will ensure that the values you are updating, have not been updated meanwhile.

If you use ExecuteNonQuery, the integer that is returned is the number of rows affected. If it is 0, no records have been updated.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.


Ok. Thanks, Eric.

Is this the practices used when working with large databases and many users?

If someone did an update to a record in question to the data table in an application that was not written by me, then the timestamp might be ignored.

This is one of the issues that confuse me. Please forgive my ignorance.

If I go to write changed data and I get a flag that something changed, I would have to see what data element changed and then resolve the issue.So, I would have to loop through every data element to see where the change took place and decide my next action. Or, would I have to return the record to the user, telling him/her that something changed and that they should review their update?

That's why I favor record-level locking. I come from the "old school" of programming databases (VSAM) and I am trying to understand disconnected datasets and data tables and data integrity. This is like a "custody of data" problem.

I am sorry for being so stupid.

Can you help me understand?


Senior .Net Consultant
Top Expert 2016
If you cannot rely on a timestamp field, you can always use another mechanism which is putting all the original values in your WHERE clause:

update X
set f1 = newvalue1
, f2 = newvalue2
, f3 = newvalue3
where f1 = oldvalue1 
and f2 = oldvalue2
and f3 = oldvalue3

Open in new window

If you really want to build a pessimistic locking system, have a look at

But I warn you that SQL is usually not locking records but pages. A pages is 8k of data. How many records in 8k? It depends on your record length!


Thank you, Eric!

Your explanation and caveats are well-respected and very appreciated. Thanks, too, for your very kind treatment and for understanding of my ignorance.

The links further-reinforce your explanations and were very helpful.

Thank you for your assistance in training me properly. You are brilliant!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial