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", intID)
Dim concurParam As New SqlParameter
concurParam.ParameterName = "@Concurrency"
concurParam.Value =
MyDataset.Tables("MyTable").Rows(0).Item("Concurre ncyValue")
concurParam.SqlDbType = SqlDbType.Binary
cmd.Parameters.Add(concurParam)
cn.Open()
If cmd.ExecuteScalar() > 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 ConcurrencyValue =
@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 5 8096
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 ConcurrencyValue = 0x000000000000906A
-- bruce (sqlwork.com)
"Bari Allen" <ba**@sos.REMOVETHIS.state.ga.us> wrote in message
news:ON**************@tk2msftngp13.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("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", intID)
Dim concurParam As New SqlParameter concurParam.ParameterName = "@Concurrency" concurParam.Value = MyDataset.Tables("MyTable").Rows(0).Item("Concurre ncyValue") concurParam.SqlDbType = SqlDbType.Binary cmd.Parameters.Add(concurParam)
cn.Open()
If cmd.ExecuteScalar() > 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 ConcurrencyValue = @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
"Bari Allen" <ba**@sos.REMOVETHIS.state.ga.us> wrote in message
news:ON**************@tk2msftngp13.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("@RowVersion", SqlDbType.Timestamp)
.Value = rowVersion
.Direction = ParameterDirection.InputOutput
End With
....
rowVersion = CType(cmd.Parameters("@RowVersion").Value, Byte())
Greg
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 uniqueidentifier
, @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 FunctionErrorWrite
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 FunctionErrorWrite
end
/* SET NOCOUNT ON */
FunctionExit:
RETURN 0
FunctionErrorUnknown:
RETURN -1
FunctionErrorWrite:
RETURN -2
FunctionErrorWrongID:
RETURN -3
FunctionErrorInterimChanged:
RETURN -4
Does this help you?
Regards
Daniel Walzenbach
"Bari Allen" <ba**@sos.REMOVETHIS.state.ga.us> schrieb im Newsbeitrag
news:ON**************@tk2msftngp13.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("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", intID)
Dim concurParam As New SqlParameter concurParam.ParameterName = "@Concurrency" concurParam.Value = MyDataset.Tables("MyTable").Rows(0).Item("Concurre ncyValue") concurParam.SqlDbType = SqlDbType.Binary cmd.Parameters.Add(concurParam)
cn.Open()
If cmd.ExecuteScalar() > 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 ConcurrencyValue = @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
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.REMOVETHIS.state.ga.us> wrote in message
news:ON**************@tk2msftngp13.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("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", intID)
Dim concurParam As New SqlParameter concurParam.ParameterName = "@Concurrency" concurParam.Value = MyDataset.Tables("MyTable").Rows(0).Item("Concurre ncyValue") concurParam.SqlDbType = SqlDbType.Binary cmd.Parameters.Add(concurParam)
cn.Open()
If cmd.ExecuteScalar() > 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 ConcurrencyValue = @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
Good to hear :-) You are welcome!
Cheers,
Daniel Walzenbach
"msnews.microsoft.com" <ba**@sos.REMOVETHIS.state.ga.us> schrieb im
Newsbeitrag news:%2***************@TK2MSFTNGP10.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.REMOVETHIS.state.ga.us> wrote in message news:ON**************@tk2msftngp13.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("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", intID)
Dim concurParam As New SqlParameter concurParam.ParameterName = "@Concurrency" concurParam.Value = MyDataset.Tables("MyTable").Rows(0).Item("Concurre ncyValue") concurParam.SqlDbType = SqlDbType.Binary cmd.Parameters.Add(concurParam)
cn.Open()
If cmd.ExecuteScalar() > 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 ConcurrencyValue = @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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= |
last post by:
(If I'm overlooking anything, please let me know.)
First, my only concern is updating single records in a Detailsview using an
ObjectDataSource. The target table has a timestamp field. Assume ...
|
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...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |