Must we use a disconnected model when creating database applications?

I am new to VB.net. 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?
Lenny GrayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
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.
0
Lenny GrayAuthor Commented:
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?

Thanks!
0
Éric MoreauSenior .Net ConsultantCommented:
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. https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery(v=vs.110).aspx
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Lenny GrayAuthor Commented:
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?

Thanks!

Lenny
0
Éric MoreauSenior .Net ConsultantCommented:
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 http://www.techrepublic.com/article/pessimistic-locking-solves-adonet-concurrency-problems/

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!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lenny GrayAuthor Commented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.