473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using timestamp (SQL Server) to maintain concurrency in ASP.NET

Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency. My
problem is how do I store the timestamp value in my webform. The hidden field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks

Nov 18 '05 #1
7 4027
Maybe by using the session object:

First request:

dtTimeStampVar DateTime;
dtTimeStampVar = // here you read the timestamp value from your SQL server
Session["timestamp"] = dtTimeStampVar
Next request:

dtTimeStampVar DateTime;
if (Session["timestamp"] != null)
dtTimeStampVar = Session["timestamp"]

Igor

"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency.
My
problem is how do I store the timestamp value in my webform. The hidden
field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to
compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks

Nov 18 '05 #2
Hi Igor:

Thanks for the reply. I think timestamp (SQL Server DataType) is not
equivalent to DateTime in .NET? So if we know the data type may be we can use
the session variable. I need to look for the correct equivalent datatype in
..NET.

Any other approach?

"Igor Kramaric" wrote:
Maybe by using the session object:

First request:

dtTimeStampVar DateTime;
dtTimeStampVar = // here you read the timestamp value from your SQL server
Session["timestamp"] = dtTimeStampVar
Next request:

dtTimeStampVar DateTime;
if (Session["timestamp"] != null)
dtTimeStampVar = Session["timestamp"]

Igor

"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency.
My
problem is how do I store the timestamp value in my webform. The hidden
field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to
compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks


Nov 18 '05 #3
Some misc. code to work with a SQL timestamp (aka rowversion):

I sometimes like making it an attribute on my page:

Here I store the original value and the rowversion...

<asp:foobar runat=server RowVersion='<%#
ByteToString(Container.DataItem("RowVersion")) %>' OriginalValue='<%#
Container.DataItem("ApprovedHours") %>' />

Protected Function ByteToString(ByVal rowVersion As Byte()) As String
Return Convert.ToBase64String(rowVersion)
End Function

Dim ApproveHours As Int16 =
CType(CType(grid.Items(selectedIndex).FindControl( "lblApproveHours"),
Label).Attributes("OriginalValue"), Int16)
Dim sRowVersion As String =
CType(CType(grid.Items(selectedIndex).FindControl( "lblApproveHours"),
Label).Attributes("RowVersion"), String)
Dim byteRowVersion() As Byte = Convert.FromBase64String(sRowVersion)

Here is how to use with a parameter...

Dim rowVersion() As Byte

With cmd.Parameters.Add("@RowVersion", SqlDbType.Timestamp)
.Value = rowVersion
.Direction = ParameterDirection.InputOutput
End With

rowVersion = CType(cmd.Parameters("@RowVersion").Value, Byte())

HTH,
Greg
"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency.
My
problem is how do I store the timestamp value in my webform. The hidden
field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to
compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks

Nov 18 '05 #4
mybappy... Also check out MSDN magazine Sept 2004 p21 Handling Data
Concurrency Using ADO.NET John Papa

Regards,
Jeff
I am trying to use timestamp field of SQL Server to maintain
concurrency.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
If you dont mind stored procedures, you might want to consider embedding
this logic within one and your application call that SP for
insert/update/deletes.

Oh, for timestamp, I think you need to use Byte array.

--
Girish Bharadwaj
http://msmvps.com/gbvb
"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
Hi Igor:

Thanks for the reply. I think timestamp (SQL Server DataType) is not
equivalent to DateTime in .NET? So if we know the data type may be we can use the session variable. I need to look for the correct equivalent datatype in .NET.

Any other approach?

"Igor Kramaric" wrote:
Maybe by using the session object:

First request:

dtTimeStampVar DateTime;
dtTimeStampVar = // here you read the timestamp value from your SQL server Session["timestamp"] = dtTimeStampVar
Next request:

dtTimeStampVar DateTime;
if (Session["timestamp"] != null)
dtTimeStampVar = Session["timestamp"]

Igor

"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency. My
problem is how do I store the timestamp value in my webform. The hidden field
does not work as I get some cast error. If I can not store the value, how should I return the timestamp to the database (with other values) to
compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks


Nov 18 '05 #6
Thanks for all of your replies. Yes I could capture timestamp using byte
array byte[] and then stored the value in session variable. I think using
session variable is not a good idea so I will try to use viewstate later ...

"Girish bharadwaj" wrote:
If you dont mind stored procedures, you might want to consider embedding
this logic within one and your application call that SP for
insert/update/deletes.

Oh, for timestamp, I think you need to use Byte array.

--
Girish Bharadwaj
http://msmvps.com/gbvb
"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com...
Hi Igor:

Thanks for the reply. I think timestamp (SQL Server DataType) is not
equivalent to DateTime in .NET? So if we know the data type may be we can

use
the session variable. I need to look for the correct equivalent datatype

in
.NET.

Any other approach?

"Igor Kramaric" wrote:
Maybe by using the session object:

First request:

dtTimeStampVar DateTime;
dtTimeStampVar = // here you read the timestamp value from your SQL server Session["timestamp"] = dtTimeStampVar
Next request:

dtTimeStampVar DateTime;
if (Session["timestamp"] != null)
dtTimeStampVar = Session["timestamp"]

Igor

"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
> Hi:
>
> I am trying to use timestamp field of SQL Server to maintain concurrency. > My
> problem is how do I store the timestamp value in my webform. The hidden > field
> does not work as I get some cast error. If I can not store the value, how > should I return the timestamp to the database (with other values) to
> compare
> with the current timestamp to check for updates.
>
> You answers will be greatly appreciated.
>
> Thanks
>


Nov 18 '05 #7
fx
Hi

Right I've decide to start giving a little back to the web
-> sorry about the delay

We've had the same 'issue' and we dug up that back in VB 6 the following
approach was used

The timestamp is essentailly a counter kinda like a database wide identity
and what they did was when you are returning the Timestamp from the database
it was cast as a bigint

So if we do the same in .NET we can throw the returned bigint into an Int64

This will take most of the hassle out of it as you'll be able to put it into
hidden text boxes etc

Cheers

Felix

PS If anyone knows of any flaws in this could you please let me know as we
are about to use it in a project

"mybappy" wrote:
Hi:

I am trying to use timestamp field of SQL Server to maintain concurrency. My
problem is how do I store the timestamp value in my webform. The hidden field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to compare
with the current timestamp to check for updates.

You answers will be greatly appreciated.

Thanks

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Astra | last post by:
Hi All I know an SQL Server timestamp seems to be as useful as rocking horse for show jumping, but I'm hoping you know a 'fudge' to get me round a problem or at least confirm that it isn't...
7
by: laurenq uantrell | last post by:
Is there any reason to have a row that is the PK/Identity and a row that is datatype Timestamp in the same table? Does this in any way help speeding up row updates? Thanks, lq
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Roger Twomey | last post by:
I have a database that I don't want to lock. I decided that before any updates can occur I would check a timestamp value and ensure that nobody else updated before I did (avoiding the 'last update...
3
by: Dean Slindee | last post by:
Since SQL Server has a native timestamp datatype, I was expecting .NET to have a .ToTimestamp function, but evidently not. Which leads to my question: is a a universally accepted format for a...
0
by: Jean-Michel POURE | last post by:
Dear friends, I am currently testing Ulogd ip traffic logging system with PostgreSQL. It works in conjunction with GNU/Linux iptables. The Ulogd project can be found here:...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
20
by: Rob Stevens | last post by:
Can someone tell me how to import the sqlite3.dll file into c#. I am pretty new to this, and I want to use sqlite. The problem is I don't have a clue on how to import the dll file so i can call...
3
by: mesut | last post by:
Hi there, I'm using a creationDate and ModifiedDate in all my tables with Datatype: DateTime. In most of my tables I need to do update/delete. Do I also need to add a field with data type...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.