Hi NG,
I am looking for an opinion here. I am new to C# and SQL, being an old
COBOL hand. I have started into a conversion of an old COBOL ERP system. I
have a number of functions working now and it is time to decide how best to
deal with the issues of concurrency. The old COBOL programs used record
locking to prevent concurrency errors and that logic is already "on the
shelf." Most C# books and articles I have seen use the default optimistic
concurrency as a way around these issues. I have coded a few test examples
and they work fine, except that you may have to tell a user to "try again."
I want to pause at this point before I code about 100 tables to get the
opinion of experienced experts on the best way to move forward. I have
noticed in books on SQL that you can do record locking down to (in some
cases) row level. This would seem like the way I wish to go. Further, I
have stayed away from SQL "Transactions" to this point, because there is a
lot I need to learn about SQL. Now may be the time to learn how to use
them. For ease of conversion I have tended to use SQL like the COBOL
programs use files. The less that SQL does, the more this project looks
like a language translation job. However, I really do want to use C# best
practices least I have an unsupportable "kludge" on my hands when I am done.
Thanks for your advice,
Bob
Robert Schuldenfrei bo*@s-i-inc.com 3 2478
Robert,
Never, ever, EVER use locking. If you do, you will be commiting your
system to death. It will NOT be scalable, period. You will hit a glass
ceiling in terms of how many operations you can support, and it will not be
pretty.
While yes, with concurrency checking, you will have to tell the user to
"try again", it is better than having corrupt data in your database, or data
that the user enters based on other data that is stale. It's generally not
a good thing. For SQL Server based solutions, I recommend the use of
timestamps, and then modifying your SQL on updates and deletes:
update <table> set <field> = <value> where id = <id> and timestamp =
<timestamp>
The delete follows the same pattern:
delete from <table> where id = <id> and timestamp = <timestamp>
The reason you do this is that from code, you can see the number of
records affected. If the number of records affected is zero, then you know
that either the id does not exist, or that the timestamp has changed, and
you can inform the user as such.
Of course, you wrap this operation in a transaction (unless it is the
only operation you are performing, since all single statements are
serializable transactions in themselves) to ensure that when you touch the
record, no one else can either, for the duration of your operation.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:kElWc.29056$9d6.17415@attbi_s54... Hi NG,
I am looking for an opinion here. I am new to C# and SQL, being an old COBOL hand. I have started into a conversion of an old COBOL ERP system. I have a number of functions working now and it is time to decide how best to deal with the issues of concurrency. The old COBOL programs used record locking to prevent concurrency errors and that logic is already "on the shelf." Most C# books and articles I have seen use the default optimistic concurrency as a way around these issues. I have coded a few test examples and they work fine, except that you may have to tell a user to "try again."
I want to pause at this point before I code about 100 tables to get the opinion of experienced experts on the best way to move forward. I have noticed in books on SQL that you can do record locking down to (in some cases) row level. This would seem like the way I wish to go. Further, I have stayed away from SQL "Transactions" to this point, because there is a lot I need to learn about SQL. Now may be the time to learn how to use them. For ease of conversion I have tended to use SQL like the COBOL programs use files. The less that SQL does, the more this project looks like a language translation job. However, I really do want to use C# best practices least I have an unsupportable "kludge" on my hands when I am done.
Thanks for your advice,
Bob
Robert Schuldenfrei bo*@s-i-inc.com
Hi Nick,
OK, I promise NEVER to even CONSIDER locking. I have two new skills to
learn: 1/ Transactions and 2/ using timestamps. I had been using a
technique of old record / new record to determine if the record had been
changed on update or delete. Timestamps seem more elegant. Sadly, the book
I have been using for learning SQL is Petkovic, SQL Server 2000, A
Beginner's Guide. He mentions timestamps, but then goes forward to
explaining locking (and not to well I might add). Can you suggest a good
book that implements your suggested approach to concurrency that would cover
both the C# and the SQL issues?
Thank you,
Bob
Robert Schuldenfrei bo*@s-i-inc.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eN*************@TK2MSFTNGP12.phx.gbl... Robert,
Never, ever, EVER use locking. If you do, you will be commiting your system to death. It will NOT be scalable, period. You will hit a glass ceiling in terms of how many operations you can support, and it will not
be pretty.
While yes, with concurrency checking, you will have to tell the user
to "try again", it is better than having corrupt data in your database, or
data that the user enters based on other data that is stale. It's generally
not a good thing. For SQL Server based solutions, I recommend the use of timestamps, and then modifying your SQL on updates and deletes:
update <table> set <field> = <value> where id = <id> and timestamp = <timestamp>
The delete follows the same pattern:
delete from <table> where id = <id> and timestamp = <timestamp>
The reason you do this is that from code, you can see the number of records affected. If the number of records affected is zero, then you
know that either the id does not exist, or that the timestamp has changed, and you can inform the user as such.
Of course, you wrap this operation in a transaction (unless it is the only operation you are performing, since all single statements are serializable transactions in themselves) to ensure that when you touch the record, no one else can either, for the duration of your operation.
Hope this helps.
Hi Bob:
This article is a good read:
Handling Data Concurrency Using ADO.NET
John Papa http://msdn.microsoft.com/msdnmag/is...s/default.aspx
--
Scott http://www.OdeToCode.com
On Mon, 23 Aug 2004 14:18:33 GMT, "Robert Schuldenfrei"
<bo*@s-i-inc.com> wrote: Hi Nick,
OK, I promise NEVER to even CONSIDER locking. I have two new skills to learn: 1/ Transactions and 2/ using timestamps. I had been using a technique of old record / new record to determine if the record had been changed on update or delete. Timestamps seem more elegant. Sadly, the book I have been using for learning SQL is Petkovic, SQL Server 2000, A Beginner's Guide. He mentions timestamps, but then goes forward to explaining locking (and not to well I might add). Can you suggest a good book that implements your suggested approach to concurrency that would cover both the C# and the SQL issues?
Thank you,
Bob
Robert Schuldenfrei bo*@s-i-inc.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eN*************@TK2MSFTNGP12.phx.gbl... Robert,
Never, ever, EVER use locking. If you do, you will be commiting your system to death. It will NOT be scalable, period. You will hit a glass ceiling in terms of how many operations you can support, and it will not be pretty.
While yes, with concurrency checking, you will have to tell the user to "try again", it is better than having corrupt data in your database, or data that the user enters based on other data that is stale. It's generally not a good thing. For SQL Server based solutions, I recommend the use of timestamps, and then modifying your SQL on updates and deletes:
update <table> set <field> = <value> where id = <id> and timestamp = <timestamp>
The delete follows the same pattern:
delete from <table> where id = <id> and timestamp = <timestamp>
The reason you do this is that from code, you can see the number of records affected. If the number of records affected is zero, then you know that either the id does not exist, or that the timestamp has changed, and you can inform the user as such.
Of course, you wrap this operation in a transaction (unless it is the only operation you are performing, since all single statements are serializable transactions in themselves) to ensure that when you touch the record, no one else can either, for the duration of your operation.
Hope this helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: aurora |
last post by:
Hello!
Just gone though an article via Slashdot titled "The Free Lunch Is Over: A
Fundamental Turn Toward Concurrency in Software"
http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues...
|
by: Peter Foti |
last post by:
Simple question... which is better to use for defining font sizes and why?
px and em seem to be the leading candidates. I know what the general answer
is going to be, but I'm hoping to ultimately...
|
by: Suzanne |
last post by:
Hi All
I'm having problems getting my data adapter to throw a concurrency
exception with an INSERT command. I want to throw a concurrency
exception if an attempt is made to enter a row into...
|
by: ardin |
last post by:
anyone please help, i am developing and application that uses the update
method of dataadapter (select, update, delete command was set by issuing
the OleDbCommandBuilder)in updating the database. ...
|
by: Robert Schuldenfrei |
last post by:
Dear NG,
I was about to "improve" concurrency checking with a Timestamp when I
discovered
that my current code is not working. After about a day of beating my head
against the wall, I am...
|
by: Homa |
last post by:
Hi,
I'm thinking what will happen if two users access a page at the same
time. If there are any local variable in the page, will this cause
concurrency problem?
Simarily, if this page need to...
|
by: corey.coughlin |
last post by:
Alright, so I've been following some of the arguments about enhancing
parallelism in python, and I've kind of been struck by how hard things
still are. It seems like what we really need is a more...
|
by: mfreeman |
last post by:
The minimal code (VB.NET 2003) needed to show this problem is shown
below. All I do is loop through the records in the table and update
them without making any changes. Out of 600 records, about...
|
by: Rotsey |
last post by:
Hi,
I have a Access 2003 talking to SQL 2005 express DB via
linked tables.
I also have .NET forms application that also talks to the
SQL DB.
I want to know how to handle concurrency in the...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |