473,748 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command

I'm trying to test for concurrency, using a SQL Stored Procedure on a
RowVersion (timestamp) Field. The vb code I'm using is as follows

Dim cmd As New SqlCommand("Con currencyCheck", cn)
Dim intID as integer = MyDataset.Table s("MyTable").Ro ws(0).Item("ID" )
cmd.CommandType = CommandType.Sto redProcedure
cmd.Parameters. Add("@ReturnVal ue", SqlDbType.Int)
cmd.Parameters( 0).Direction = ParameterDirect ion.ReturnValue
cmd.Parameters. Add("@ID", intID)

Dim concurParam As New SqlParameter
concurParam.Par ameterName = "@Concurren cy"
concurParam.Val ue =
MyDataset.Table s("MyTable").Ro ws(0).Item("Con currencyValue")
concurParam.Sql DbType = SqlDbType.Binar y
cmd.Parameters. Add(concurParam )

cn.Open()

If cmd.ExecuteScal ar() > 0 Then
Record Found ...
Else
Record not found ...
End If

cmd.Dispose()
cn.Close()
cn.Dispose()

Prior to submitting the form, I run a different stored procedure which
populates the "MyDataset" from the same row using:
SELECT * FROM MyTable WHERE ID = @ID

The code in the stored procedure that submits the form is:
SELECT Count(*) FROM MyTable WHERE ID = @ID AND ConcurrencyValu e =
@Concurrency

How do I convert the originally retrieved data (RowVersion) back to a true
binary in ASP.NET to send it back to SQL? It currently is storing the field
as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"

Thanks in advance for any help on this.

Bari
Nov 20 '05 #1
5 2718
a sql timestamp should come across as an 8 byte binary array. be sure to
specify size of 8. sql wants an 8 byte literal.

SELECT Count(*) FROM MyTable
WHERE ID = @ID
AND ConcurrencyValu e = 0x0000000000009 06A

-- bruce (sqlwork.com)
"Bari Allen" <ba**@sos.REMOV ETHIS.state.ga. us> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
I'm trying to test for concurrency, using a SQL Stored Procedure on a
RowVersion (timestamp) Field. The vb code I'm using is as follows

Dim cmd As New SqlCommand("Con currencyCheck", cn)
Dim intID as integer = MyDataset.Table s("MyTable").Ro ws(0).Item("ID" )
cmd.CommandType = CommandType.Sto redProcedure
cmd.Parameters. Add("@ReturnVal ue", SqlDbType.Int)
cmd.Parameters( 0).Direction = ParameterDirect ion.ReturnValue
cmd.Parameters. Add("@ID", intID)

Dim concurParam As New SqlParameter
concurParam.Par ameterName = "@Concurren cy"
concurParam.Val ue =
MyDataset.Table s("MyTable").Ro ws(0).Item("Con currencyValue")
concurParam.Sql DbType = SqlDbType.Binar y
cmd.Parameters. Add(concurParam )

cn.Open()

If cmd.ExecuteScal ar() > 0 Then
Record Found ...
Else
Record not found ...
End If

cmd.Dispose()
cn.Close()
cn.Dispose()

Prior to submitting the form, I run a different stored procedure which
populates the "MyDataset" from the same row using:
SELECT * FROM MyTable WHERE ID = @ID

The code in the stored procedure that submits the form is:
SELECT Count(*) FROM MyTable WHERE ID = @ID AND ConcurrencyValu e =
@Concurrency

How do I convert the originally retrieved data (RowVersion) back to a true
binary in ASP.NET to send it back to SQL? It currently is storing the
field
as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"

Thanks in advance for any help on this.

Bari

Nov 20 '05 #2
"Bari Allen" <ba**@sos.REMOV ETHIS.state.ga. us> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
How do I convert the originally retrieved data (RowVersion) back to a true
binary in ASP.NET to send it back to SQL? It currently is storing the
field
as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"


Here is some code I grabbed that is using RowVersion and converting back and
forth...

Dim rowVersion(8) As Byte
....
With cmd.Parameters. Add("@RowVersio n", SqlDbType.Times tamp)
.Value = rowVersion
.Direction = ParameterDirect ion.InputOutput
End With
....
rowVersion = CType(cmd.Param eters("@RowVers ion").Value, Byte())

Greg

Nov 20 '05 #3
Bari,

what I do is that I convert the TimeStamp value in a BigInt value which I
can easily pass back and forth to my stored proc. An example would look like
the following:

CREATE PROCEDURE dbo.spTest
(
@OIDTest uniqueidentifie r
, @SomeValue as int

, @VersionOld bigint = 0 output
)

AS

declare @Error int
declare @rowcount int

update tblTest set

SomeValue = @SomeValue

where OIDTest = @OIDTest and TimeStp = @VersionOld
select @error = @@error, @rowcount = @@rowcount

if @error > 0
begin
-- an error occurred
goto FunctionErrorWr ite
end

if (@rowcount = 1)
begin
-- everything is fine

-- get a new timeStamp
select @VersionOld = convert(bigint, TimeStp)
from tblTest
where OIDTest = @OIDTest
-- Transaktion durchführen
goto FunctionExit
end
else
begin
goto FunctionErrorWr ite
end
/* SET NOCOUNT ON */
FunctionExit:
RETURN 0

FunctionErrorUn known:
RETURN -1

FunctionErrorWr ite:
RETURN -2

FunctionErrorWr ongID:
RETURN -3

FunctionErrorIn terimChanged:
RETURN -4

Does this help you?

Regards

Daniel Walzenbach


"Bari Allen" <ba**@sos.REMOV ETHIS.state.ga. us> schrieb im Newsbeitrag
news:ON******** ******@tk2msftn gp13.phx.gbl...
I'm trying to test for concurrency, using a SQL Stored Procedure on a
RowVersion (timestamp) Field. The vb code I'm using is as follows

Dim cmd As New SqlCommand("Con currencyCheck", cn)
Dim intID as integer = MyDataset.Table s("MyTable").Ro ws(0).Item("ID" )
cmd.CommandType = CommandType.Sto redProcedure
cmd.Parameters. Add("@ReturnVal ue", SqlDbType.Int)
cmd.Parameters( 0).Direction = ParameterDirect ion.ReturnValue
cmd.Parameters. Add("@ID", intID)

Dim concurParam As New SqlParameter
concurParam.Par ameterName = "@Concurren cy"
concurParam.Val ue =
MyDataset.Table s("MyTable").Ro ws(0).Item("Con currencyValue")
concurParam.Sql DbType = SqlDbType.Binar y
cmd.Parameters. Add(concurParam )

cn.Open()

If cmd.ExecuteScal ar() > 0 Then
Record Found ...
Else
Record not found ...
End If

cmd.Dispose()
cn.Close()
cn.Dispose()

Prior to submitting the form, I run a different stored procedure which
populates the "MyDataset" from the same row using:
SELECT * FROM MyTable WHERE ID = @ID

The code in the stored procedure that submits the form is:
SELECT Count(*) FROM MyTable WHERE ID = @ID AND ConcurrencyValu e =
@Concurrency

How do I convert the originally retrieved data (RowVersion) back to a true
binary in ASP.NET to send it back to SQL? It currently is storing the
field
as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"

Thanks in advance for any help on this.

Bari

Nov 20 '05 #4
Thank you to everyone that replied.

When I tried to convert a value from a field in the dataset's table to byte,
I got an error, because the implicit conversion wasn't allowed from an array
(the default conversion sent back from the timestamp column).

Thus, I went with Daniel's suggestion to convert the value to a BigInt
within the retrieval stored procedure's select statement. That way, I can
store the entire recordset in a dataset, when it is returned. Then, I send
back the BigInt value to the stored procedure that tests for concurrency
(for updates). This worked great.

Thank you, Daniel!

"Bari Allen" <ba**@sos.REMOV ETHIS.state.ga. us> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
I'm trying to test for concurrency, using a SQL Stored Procedure on a
RowVersion (timestamp) Field. The vb code I'm using is as follows

Dim cmd As New SqlCommand("Con currencyCheck", cn)
Dim intID as integer = MyDataset.Table s("MyTable").Ro ws(0).Item("ID" )
cmd.CommandType = CommandType.Sto redProcedure
cmd.Parameters. Add("@ReturnVal ue", SqlDbType.Int)
cmd.Parameters( 0).Direction = ParameterDirect ion.ReturnValue
cmd.Parameters. Add("@ID", intID)

Dim concurParam As New SqlParameter
concurParam.Par ameterName = "@Concurren cy"
concurParam.Val ue =
MyDataset.Table s("MyTable").Ro ws(0).Item("Con currencyValue")
concurParam.Sql DbType = SqlDbType.Binar y
cmd.Parameters. Add(concurParam )

cn.Open()

If cmd.ExecuteScal ar() > 0 Then
Record Found ...
Else
Record not found ...
End If

cmd.Dispose()
cn.Close()
cn.Dispose()

Prior to submitting the form, I run a different stored procedure which
populates the "MyDataset" from the same row using:
SELECT * FROM MyTable WHERE ID = @ID

The code in the stored procedure that submits the form is:
SELECT Count(*) FROM MyTable WHERE ID = @ID AND ConcurrencyValu e =
@Concurrency

How do I convert the originally retrieved data (RowVersion) back to a true
binary in ASP.NET to send it back to SQL? It currently is storing the field as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"

Thanks in advance for any help on this.

Bari

Nov 20 '05 #5
Good to hear :-) You are welcome!

Cheers,

Daniel Walzenbach

"msnews.microso ft.com" <ba**@sos.REMOV ETHIS.state.ga. us> schrieb im
Newsbeitrag news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
Thank you to everyone that replied.

When I tried to convert a value from a field in the dataset's table to
byte,
I got an error, because the implicit conversion wasn't allowed from an
array
(the default conversion sent back from the timestamp column).

Thus, I went with Daniel's suggestion to convert the value to a BigInt
within the retrieval stored procedure's select statement. That way, I can
store the entire recordset in a dataset, when it is returned. Then, I
send
back the BigInt value to the stored procedure that tests for concurrency
(for updates). This worked great.

Thank you, Daniel!

"Bari Allen" <ba**@sos.REMOV ETHIS.state.ga. us> wrote in message
news:ON******** ******@tk2msftn gp13.phx.gbl...
I'm trying to test for concurrency, using a SQL Stored Procedure on a
RowVersion (timestamp) Field. The vb code I'm using is as follows

Dim cmd As New SqlCommand("Con currencyCheck", cn)
Dim intID as integer = MyDataset.Table s("MyTable").Ro ws(0).Item("ID" )
cmd.CommandType = CommandType.Sto redProcedure
cmd.Parameters. Add("@ReturnVal ue", SqlDbType.Int)
cmd.Parameters( 0).Direction = ParameterDirect ion.ReturnValue
cmd.Parameters. Add("@ID", intID)

Dim concurParam As New SqlParameter
concurParam.Par ameterName = "@Concurren cy"
concurParam.Val ue =
MyDataset.Table s("MyTable").Ro ws(0).Item("Con currencyValue")
concurParam.Sql DbType = SqlDbType.Binar y
cmd.Parameters. Add(concurParam )

cn.Open()

If cmd.ExecuteScal ar() > 0 Then
Record Found ...
Else
Record not found ...
End If

cmd.Dispose()
cn.Close()
cn.Dispose()

Prior to submitting the form, I run a different stored procedure which
populates the "MyDataset" from the same row using:
SELECT * FROM MyTable WHERE ID = @ID

The code in the stored procedure that submits the form is:
SELECT Count(*) FROM MyTable WHERE ID = @ID AND ConcurrencyValu e =
@Concurrency

How do I convert the originally retrieved data (RowVersion) back to a
true
binary in ASP.NET to send it back to SQL? It currently is storing the

field
as an array, for some reason. Thus, when I test this procedure and now
(without a doubt) no one has modified the record since, it ALWAYS returns
"record not found"

Thanks in advance for any help on this.

Bari


Nov 20 '05 #6

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

Similar topics

2
7323
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE provider. Precisely, here is the code i have Dim Cmdobj As New ADODB.Command Cmdobj.ActiveConnection = oconn Cmdobj.CommandType = adCmdStoredProc
4
2293
by: Charlie Williams | last post by:
I am having difficulty performing updates and deletions on an Access database using the Update() method of the OleDBDataAdapter. I can insert rows without a problem, but I get a concurrency exception when trying to update or delete. I am quite sure that no concurrency conflicts actually exist. Is there a reason why the data adapter I am using may have a different row version that the database that it got its data from?
2
5121
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create, read, update, delete data in a SQL Server 2000 data store. I've done a fair amount of research on concurrency handling in newsgroups and other resources. Below is what I've come up as a standard for handling concurrency thru stored procedures. I am sharing with everyone so I can get some comments...
5
1485
by: Steve | last post by:
Visual Studio 2003 .Net / C# / SQL 2000 I am trying to work out the best way to ensure data concurrency in my application. All updates and inserts etc are done via stored procedures. When a user enters a screen i call a stored procedure which returns me a record or many records and display them in my screen. When they insert a record I just call a stored procedure passing over all the screen values, and the same with updating records. ...
7
4060
by: mybappy | last post by:
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.
8
5039
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
5
8121
by: Bari Allen | last post by:
I'm trying to test for concurrency, using a SQL Stored Procedure on a RowVersion (timestamp) Field. The vb code I'm using is as follows Dim cmd As New SqlCommand("ConcurrencyCheck", cn) Dim intID as integer = MyDataset.Tables("MyTable").Rows(0).Item("ID") cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@ReturnValue", SqlDbType.Int) cmd.Parameters(0).Direction = ParameterDirection.ReturnValue cmd.Parameters.Add("@ID",...
4
1579
by: Andrew Robinson | last post by:
I am working on a system system that requires optimistic concurrency within a web app. At first I thought this would be easy. We generate our own entities and dal/service layer but I now see that working with controls like a grid view pose some very complicated issues. If I am using rowversion, when do I start the "clock"? When I first display the label version of a field? when I display the data within a textbox for edit or when I read...
7
1810
by: John | last post by:
Hi I have asked this question before but have not received any clear answer. I have a winform app with bound controls via dataadapter/dataset combination.I have a dbconcurrency exception ex. Now I have the following; DataRow = ex.Row DataTable = ex.Row.Table DataColumns = ex.Row.Table.Columns DataSet = ex.row.Table.Dataset
0
8984
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.