We help IT Professionals succeed at work.

Must we use a disconnected model when creating database applications?

Lenny Gray
Lenny Gray asked
on
73 Views
Last Modified: 2017-03-22
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?
Comment
Watch Question

Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
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.
Lenny GrayProgrammer

Author

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!
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
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
Lenny GrayProgrammer

Author

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
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Lenny GrayProgrammer

Author

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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions