Last post Feb 19, 2015 03:18 AM by Kevin Shen - MSFT
Feb 18, 2015 03:59 PM|Davidb55|LINK
I am developing an ASP.NET 4 SaaS application (Migrating a windows application) that uses a sql database, but the data is unique to each client.
I have one database that contains the client id and stores the database connection information and the actual client database.
In a Win Forms app (VB) I figured out how to have one login window with client id, user id and password. When client would click on the log in button it would validate their client ID and pull the DB connection information and open the client DB validate
the User ID and Password and make the database available to the rest of the application.
I am new to the ASP.NET world and am having trouble figuring out how to do this and make the transition.
Assistance would be greatly appreciated.
Can anyone point me in the right direction?
Feb 19, 2015 02:31 AM|Mikesdotnetting|LINK
If you want to retain data on a user-by-user basis. one way to do this is using Sessions. When the user logs in, you obtain their connection string from your db and store it as a session variable:
Session["ConnString"] = their_connection_string;
Then you can pass that value to whatever needs it:
using(SqlConnection conn = new SqlConnection(Session["ConnString"]))
You must check that Session["ConnString"] is not null before attempting to use it. as session data is stored in Server RAM and is volatile. If it is null, just repopulate the variable with data from the database.
Ref: ASP.NET Session State Overview
Feb 19, 2015 03:18 AM|Kevin Shen - MSFT|LINK
As far as i know ,when you user log in the system,you first check its user id and password.
After user has been validated successfully ,you could get the connections based on the user id .
Then create connection to database like below:
SqlConnection conn=new SqlConnection("yourconnectionstring")