# Web application and multiple sessions

**URL:** <https://forums.visual-paradigm.com/t/web-application-and-multiple-sessions/9993>\
**Category:** General Questions/Discussions\
**Created:** [December 19, 2007, 7:31pm UTC](https://forums.visual-paradigm.com/t/web-application-and-multiple-sessions/9993 "2007-12-19T19:31:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hectoret](https://avatars.discourse-cdn.com/v2/letter/h/45deac/32.png) [@hectoret](https://forums.visual-paradigm.com/u/hectoret)\
**Post date:** [December 19, 2007, 7:31pm UTC](https://forums.visual-paradigm.com/t/web-application-and-multiple-sessions/9993/1 "2007-12-19T19:31:16Z")

</div>

I am working on a web application that runs under Visual Studio 2005, language C#. I designed with Visual Paradigm the classes diagram and automatically generated the database and code with the VP tools.

The Perstent API type I used for code generation is “Static Methods”, I think is the most simple and ok for me.

I created a class called dao.cs so it contains every access to the database and connections. It looks like this:

public class dao  
{  
private PersistentManager persistenceManager = HMIPersistentManager.Instance();

```
private static dao instance = null;

private dao()
{
}

public static dao getInstance()
{
	if (instance == null)
		instance = new dao();
	return instance;
}

     public Recipe getRecipeByID(int id)
{
	PersistentTransaction t = this.persistenceManager.GetSession().BeginTransaction();

	Recipe a = Recipe.LoadRecipeByORMID(id);

	t.Commit(); // <<-- exception here: already opened conexion or ID already in use....
	return a;
}

    /* more methods... */

```

}

The problem is, when executing the project, sometimes it throws an exception on the “t.Commit();” line. I would like to implement the best way for a web application: multiple users accessing the database, and everything running fine.

Do I need to use a lock like:  
PersistentManager.instance().getSession().lock(obj, LockMode.NONE);

Where do I put it? Which lockmode choose?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Rain](https://forums.visual-paradigm.com/user_avatar/forums.visual-paradigm.com/rain/32/2309_2.png) [@Rain](https://forums.visual-paradigm.com/u/Rain)\
**Post date:** [December 21, 2007, 6:26pm UTC](https://forums.visual-paradigm.com/t/web-application-and-multiple-sessions/9993/2 "2007-12-21T18:26:26Z")

</div>

Hi hectoret,

When running in web environment, please make sure have

1. close session before return values

2. running thread based session

XXPersistentManager.SetSessionType(PersistentManager.SessionType.THREAD\_BASE);

Hope this helps.

Best regards,  
Rain
