Avatar of Sonny G
Sonny G
 asked on

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?
SQLVisual Basic.NET

Avatar of undefined
Last Comment
Sonny G

8/22/2022 - Mon
Éric Moreau

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.
Sonny G

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 Moreau

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Sonny G

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?


Éric Moreau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sonny G

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!