Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Concurrency with Timestamp
Message
From
02/07/2008 17:42:15
 
 
To
27/06/2008 12:21:40
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 3.0
Database:
MS SQL Server
Miscellaneous
Thread ID:
01327229
Message ID:
01328464
Views:
15
Hi Kevin,

I am still having problems figuring out concurrency control with timestamps. I have used the BLG to generate against the following SP
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[SQLTrac_Resources_ViewUpdate]
(
	@Author int,
	@Created smalldatetime,
	@Declaration varchar(100),
	@DetailTxt text,
	@ForDept char(4),
	@ForEmp int,
	@Grp int,
	@LastModified smalldatetime,
	@ModifiesData bit,
	@ResourceID int,
	@ResourceName varchar(50),
	@ResourceTxt text,
	@ReturnType char(20),
	@ShortDescrip varchar(500),
	@SystemName varchar(50),
	@TimeStamp timestamp,
	@Type int
)
AS
	SET NOCOUNT OFF;
	UPDATE [dbo].[SQLTrac_Resources]
	SET 
		[Author] = @Author,
		[Created] = @Created,
		[Declaration] = @Declaration,
		[DetailTxt] = @DetailTxt,
		[ForDept] = @ForDept,
		[ForEmp] = @ForEmp,
		[Grp] = @Grp,
		[LastModified] = @LastModified,
		[ModifiesData] = @ModifiesData,
		[ResourceName] = @ResourceName,
		[ResourceTxt] = @ResourceTxt,
		[ReturnType] = @ReturnType,
		[ShortDescrip] = @ShortDescrip,
		[SystemName] = @SystemName,
		[Type] = @Type
		 
	WHERE 
	(
		([ResourceID] = @ResourceID) AND
		([TimeStamp] = @TimeStamp)
		
	);
	
	SELECT 
		[Author], 
		[Created], 
		[Declaration], 
		[DetailTxt], 
		[ForDept], 
		[ForEmp], 
		[Grp], 
		[GrpName], 
		[LastModified], 
		[ModifiesData], 
		[ResourceID], 
		[ResourceName], 
		[ResourceTxt], 
		[ReturnType], 
		[ShortDescrip], 
		[SystemName], 
		[Type], 
		[TypeName],
		[TimeStamp]
	FROM [dbo].[SQLTrac_Resources_View]
	WHERE
		([ResourceID] = @ResourceID)
		
The BLG generated the follow update code which appears to be correct:
	/// <summary>
		/// Update Command Factory method
		/// </summary>
		/// <returns>Update Command</returns>
		public override System.Data.IDbCommand CreateUpdateCommand()
		{
			System.Data.SqlClient.SqlCommand UpdateCommand = (System.Data.SqlClient.SqlCommand)this.CreateCommand("dbo.SQLTrac_Resources_ViewUpdate");
			UpdateCommand.CommandType = System.Data.CommandType.StoredProcedure;
				UpdateCommand.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {
				new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((byte)(0)), ((byte)(0)), "", System.Data.DataRowVersion.Current, null),
				new System.Data.SqlClient.SqlParameter("@Author", System.Data.SqlDbType.Int, 4, "Author"),
				new System.Data.SqlClient.SqlParameter("@Created", System.Data.SqlDbType.SmallDateTime, 4, "Created"),
				new System.Data.SqlClient.SqlParameter("@Declaration", System.Data.SqlDbType.VarChar, 100, "Declaration"),
				new System.Data.SqlClient.SqlParameter("@DetailTxt", System.Data.SqlDbType.Text, 2147483647, "DetailTxt"),
				new System.Data.SqlClient.SqlParameter("@ForDept", System.Data.SqlDbType.Char, 4, "ForDept"),
				new System.Data.SqlClient.SqlParameter("@ForEmp", System.Data.SqlDbType.Int, 4, "ForEmp"),
				new System.Data.SqlClient.SqlParameter("@Grp", System.Data.SqlDbType.Int, 4, "Grp"),
				new System.Data.SqlClient.SqlParameter("@LastModified", System.Data.SqlDbType.SmallDateTime, 4, "LastModified"),
				new System.Data.SqlClient.SqlParameter("@ModifiesData", System.Data.SqlDbType.Bit, 1, "ModifiesData"),
				new System.Data.SqlClient.SqlParameter("@ResourceID", System.Data.SqlDbType.Int, 4, "ResourceID"),
				new System.Data.SqlClient.SqlParameter("@ResourceName", System.Data.SqlDbType.VarChar, 50, "ResourceName"),
				new System.Data.SqlClient.SqlParameter("@ResourceTxt", System.Data.SqlDbType.Text, 2147483647, "ResourceTxt"),
				new System.Data.SqlClient.SqlParameter("@ReturnType", System.Data.SqlDbType.Char, 20, "ReturnType"),
				new System.Data.SqlClient.SqlParameter("@ShortDescrip", System.Data.SqlDbType.VarChar, 500, "ShortDescrip"),
				new System.Data.SqlClient.SqlParameter("@SystemName", System.Data.SqlDbType.VarChar, 50, "SystemName"),
				new System.Data.SqlClient.SqlParameter("@TimeStamp", System.Data.SqlDbType.Timestamp, 8, "TimeStamp"),
				new System.Data.SqlClient.SqlParameter("@Type", System.Data.SqlDbType.Int, 4, "Type")});
			return UpdateCommand;
		}
When I run the following test jig I should get a concurrency error, but I don't. What am I missing?
     [Test]
        public void ConcurrencyTest()
        {
            // first read in a resource entity
            SQLTracResource resource1 = new SQLTracResource();
            resource1.Entity = resource1.GetResourceByID(14);
            if (resource1.Entity.HasValues)
            {
                // change some values
                resource1.Entity.ResourceName = "My Stored Procedure - "+DateTime.Now.ToLongTimeString();
                resource1.Entity.ReturnType = "varchar(100)";

                // put a debug break here to change data via other tool
                Console.Out.WriteLine("Concurrency test: " + resource1.Entity.ResourceName);

                // now try and save the entity
                mmSaveDataResult result = resource1.SaveEntity();
                if (result == mmSaveDataResult.RulesBroken)
                {
                    Console.Out.WriteLine(resource1.Rules.GetAllBrokenRules());
                }

                Assert.That(result == mmSaveDataResult.RulesBroken, "Opps, should have broken a concurrency rule...");
            }
            else
            {
                Assert.That(false, "No values");
            }
        }
Previous
Reply
Map
View

Click here to load this message in the networking platform