SQL: Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRAN is missing.

The following error message is got when the number of open transactions is different than the number of committed or rolled back transaction in the end of the stored procedure.

The global variable @@TRANCOUNT gives the number of opened transactions in the moment of check-up. If you are not sure what is number of opened transactions you can check the number at the end of the procedure and commit or rollback.

DECLARE @TranStarted bit
SET @TranStarted = 0

IF( @@TRANCOUNT = 0 )
BEGIN
BEGIN TRANSACTION
SET @TranStarted = 1
END
ELSE
SET @TranStarted = 0

-- do something
-- use select statements with locking rows or tables using
-- WITH ( UPDLOCK, HOLDLOCK ), WITH (HOLDLOCK)

IF( @@ERROR <> 0 )
GOTO Cleanup

--do something


IF( @@ERROR <> 0 )
GOTO Cleanup


-- if no errors commit the transaction
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
COMMIT TRANSACTION
END

RETURN 1

-- in case of errors jump to the label cleanup to rollback the transaction
Cleanup:

IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
ROLLBACK TRANSACTION
END

RETURN 0

History support on Microsoft Ajax Library 3.5 SP1

The history control maintain the browser back button. An explanation of the feature is located in the Readme documentation of the Microsoft Ajax Library 3.5 SP1 package.
For quick reference the links are listed below:


In order to allow the browser history feature without using the server-side ScriptManager control, it is necessary to add the following markup into the page for Internet Explorer versions before 8:

<iframe id="__historyFrame" src="/System.Web.Extensions/3.5.0.0/3.5.30729.1/empty.htm" style="display:none;"></iframe>

C# Implicitly Typed Local Variables and Arrays

As a whole C# is a strongly-typed language. In other word the C# variables can hold explicitly defined data type.

From C# version 3.0 on the developer get the possibility to assign any values to a variable and the compiler to obtain accordingly the data type. It is not in the C# style as we know it but has some advantages of course.

var intVariable = 1235;
var stringVariable = "Hello";

The var keyword instructs the compiler to infer the type of the variable from the expression on the right side of the initialization statement. The may be a built-in type, an anonymous type, a user-defined type, or a type defined in the .NET Framework class library.

The biggest advantage of this new feature is the usage in LINQ query expression using anonymous data types. The anonymous type name is automatically generated by the compiler and is not available at the source code level, but his usage saves much developer's efforts.

For more information in MSDN click here

How to get the value of the server variable LOGON_USER

1. Uncheck Allow Anonymous in the security tab of the site properties in IIS. At least Basic or Windows Authetication is needed.

2. Use the variable Request.ServerVariables("LOGON_USER") to get the full user name