Building Multi-Tenant Applications - Dynamic Connection Strings
Description
A multi-tenant application is an application that is shared by many different customers. Salesforce.com is a good example of a multi-tenant application. There are typically two different approaches to building a multi-tenant application. These are:
All tenants share the same database, but each table in the database has a 'tenantId' field which identifies the tenant. Every query that is executed includes the tenantId in the WHERE clause. The tentantId is set when the customer logs into the application.
Each tenant has its own database.
The second approach is much easier to code because you don't have worry about adding the 'tenantId' field into every query and insert statement. However, it is less scalable because you need to provision a new database for every tenant. To support the second approach it is necessary to have 'dynamic' named connections. Here is how dynamic connections work: You must name your connection string 'DynamicConnection_<some name of your choice>'. For example:
DynamicConnection_MyAppConnection
Then, after the user has logged in, you must have an A5W page that sets a protected session variable called '__protected__<some name of your choice>'. For example:
session.__protected__MyAppConnection = "Your connection string"
When the user runs a Grid or UX component, if the named connection string starts with 'DynamicConnection_', then Alpha Anywhere will look for the appropriate protected session variable. If the variable exists, the named connection will be resolved to the value of the protected session variable. If the variable does not exist, then the named connection string will be resolved in the standard way, by looking up its value from data defined in the a5_application.a5i file.
See Also