Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 11-18-2005, 08:45 PM   #1
Default 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("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
  Reply With Quote
Old 11-18-2005, 09:23 PM   #2
Bruce Barker
 
Posts: n/a
Default Re: Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command
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" <> wrote in message
news:...
> 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
>
>





Bruce Barker
  Reply With Quote
Old 11-18-2005, 09:27 PM   #3
Greg Burns
 
Posts: n/a
Default Re: Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command
"Bari Allen" <> wrote in message
news:...
> 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( As Byte
....
With cmd.Parameters.Add("@RowVersion", SqlDbType.Timestamp)
.Value = rowVersion
.Direction = ParameterDirection.InputOutput
End With
....
rowVersion = CType(cmd.Parameters("@RowVersion").Value, Byte())

Greg





Greg Burns
  Reply With Quote
Old 11-18-2005, 11:53 PM   #4
Daniel Walzenbach
 
Posts: n/a
Default Re: Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command
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" <> schrieb im Newsbeitrag
news:...
> 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
>
>





Daniel Walzenbach
  Reply With Quote
Old 11-20-2005, 04:25 AM   #5
msnews.microsoft.com
 
Posts: n/a
Default Re: Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command
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" <> wrote in message
news:...
> 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
>
>





msnews.microsoft.com
  Reply With Quote
Old 11-20-2005, 01:19 PM   #6
Daniel Walzenbach
 
Posts: n/a
Default Re: Concurrency Checking - SQL Server Rowversion - Stored Procedures ASP.NET Command
Good to hear You are welcome!

Cheers,

Daniel Walzenbach

"msnews.microsoft.com" <> schrieb im
Newsbeitrag news:%...
> 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" <> wrote in message
> news:...
>> 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
>>
>>

>
>





Daniel Walzenbach
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Demo projects in Asp.net with C# and sql server?? CouponAlbum General Help Related Topics 0 05-01-2009 01:17 PM
Prerequisites 70-745 (Business Intelligence) Valmont MCITP 3 06-24-2008 03:03 PM
SQL Server 2008 delayed into Q3 2008 darrilgibson@cox.net MCITP 0 01-27-2008 10:26 PM
help me for SQL server 2000 and ASP.NET rishabhsethi General Help Related Topics 0 12-27-2007 10:19 AM
MCITP SQL Server 2005 or SQL Server 2008 Darrilgibson@gmail.com MCITP 0 12-19-2007 01:56 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46