I think you should add some control statements in your code and throw exceptions and/or write to a log file if something is amiss.
You can do this in several places in order to narrow down where your error origins.
1. Check if the property AUSORD.DataAccess.Common.LoginName is changed anywhere else in the code.
2. In the method
Application_PostAuthenticateRequest
protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
throw new ArgumentNullException();
AUSORD.DataAccess.Common.LoginName = HttpContext.Current.User.Identity.Name;
}
3. In the method
GetConnectionAT
public static SqlConnection GetConnectionAT(string loginName)
{
if (String.IsNullOrEmpty(loginName))
throw new ArgumentNullException();
}
4. In the stored procedure
CREATE PROCEDURE [dbo].[SetATUser]
@loginName AS VARCHAR(100)
AS
BEGIN
DECLARE @userId INT
DECLARE @ctx VARBINARY(128)
IF (ISNULL(@loginName) OR @loginName = '') THEN
END IF
SELECT @userId = UserId
FROM Users
WHERE LoginName = @loginName
IF (ISNULL(@userId) OR @userId = '') THEN
END IF
SET @ctx = CAST(@userId AS VARBINARY(128))
SET CONTEXT_INFO @ctx
END
(Very sorry for the MySQL syntax, but I'm most familiar with that.)
It might seem to be overkill to do checks in so many different places, but you might change the code later on and make calls from other parts of the code.
If you decide to write error info to a log file, I suggest that you add a time stamp and perhaps system information such as CPU load, memory usage and a list of active processes.
This info can be helpful to identify patterns, such as the error only occurs at a specific time of the day, or the memory starts to reach the maximum or a specific process is taking more CPU speed than normal, e.g. virus protection.
You don't say if you are running the same software on many computers.
If so it can be useful to check if the error occurs on all machines or just a few or maybe only one. In that case, what is the difference between a working and non working PC?
Do a list of both HW and SW to see if you can spot any potential culprit.
I know this is not a direct solution to your problem, but maybe you can find these tips useful.