By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,082 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,082 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.