Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DatabaseSets in Webapplication
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01025171
Message ID:
01026612
Vues:
20
Thomas,

>I have the problem, that I have to deal with several databases in a webapplication for several customers.
>My question is now how do I switch between the different databasesetKeys based on the logged in user???
>My current idea is to store it in the Session and then update the databaseMgr in every page_load like this:
>mmAppBase.DatabaseMgr.DatabaseSetKey = (string)Session["DatabaseKey"];
>
>But as the DatabaseMgr is application wide available, this might crash when the applications is in use from several user at the same time.
>
>Any ideas to that? As I am pretty new to MM .NET it might be possible that I havent found a solution to this in the documentation.

If you want to do something like this on the web on a per user basis, since business objects can't retrieve information from a user session, you need to set this information on the business object each time you instantiate it. First of all you can change your ABusinessObject definition as follows:
public class ABusinessObject : mmBusinessObject
{
	protected string DatabaseSetKey;

	/// <summary>
	/// Constructor
	/// </summary>
	public ABusinessObject()
	{
		this.DatabaseKey = "Northwind";
		this.RetrieveAutoIncrementPK = true;
	}

	public void SetDatabaseSetKey(string databaseSetKey)
	{
		this.DatabaseSetKey = databaseSetKey;
		mmDataAccessBase dao = this.GetDataAccessObject();
		if (dao != null)
		{
			dao.DatabaseSetKey = databaseSetKey;
		}
	}

	public override mmDataAccessBase GetDataAccessObject()
	{
		mmDataAccessBase dao = base.GetDataAccessObject ();
		if (this.DatabaseSetKey != null)
		{
			dao.DatabaseSetKey = this.DatabaseSetKey;
		}
		return dao;
	}
}
Then when you instantiate your business object in a web page you can retrieve the correct database set key and call the business object's SetDatabaseSetKey() method. For example:
this.oInventory = new Inventory();
this.oInventory.SetDatabaseSetKey("DATABASE SET VALUE");
Now when the data access object is instantiated (which happens the first time you try to access data), the GetDataAccessObject() method will set the data access object's DatabaseSetKey property to the correct value for the current user.

Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform