Nhibernate error :Incorrect syntax near the keyword ‘Function’.

In our database sometimes we have column names which are actually the database keywords . If we want to access such columns from Nhibernate session  , it throws error message “Incorrect syntax near the word :’SOME DB KEYWORD’

 

Mapping :Before :

Mapping :After

Keeping database base reserve keyword in “[ ]”  brackets will fix the error message.

 

You can have look on all my previous Nhibernate posts

 

 

 

 

 

 

 

 

 

 

 

Advertisements

Get total number of users accessing web application

In my application , we have to display the total number of users who were accessign the hosted web application at any point of time . To implement this requirement , i have made some changes in the Global.Asax file of the application . Here is the code snippet.Hope this will help  you .

<%@ Application %>

<script RunAt=”server”>

void Application_Start(object sender, EventArgs e)

{

// Code that runs on application startup

Application.Add(“ActiveUsers”, 0);

}

void Application_End(object sender, EventArgs e)

{

// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)

{

// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)

{

// Code that runs when a new session is started

Application.Lock();

Application[“ActiveUsers”] = System.Convert.ToInt32(Application[“ActiveUsers”]) + 1;

Application.UnLock();

}

void Session_End(object sender, EventArgs e)

{

// Code that runs when a session ends.

// Note: The Session_End event is raised only when the sessionstate mode

// is set to InProc in the Web.config file. If session mode is set to StateServer

// or SQLServer, the event is not raised.

Application.Lock();

Application[“ActiveUsers”] = System.Convert.ToInt32(Application[“ActiveUsers”]) – 1;

Application.UnLock();

}

</script>

 Now you can retrieve number of active users     —  Application.Get(“ActiveUsers”).ToString()