mosyflasher
mosyflasher

Reputation: 499

Use 2(or more) Database in one asp application and switch connection string

i have one ASP application and i want to use that for 2(or more) place and each of them has their Database , now is there a way to change connection string when user log in? or anyway to change database for each user?

i saw this question before

How to setup single-code multiple-database ASP.NET SaaS application

but i couldn't figure out how it works!

please help me

EDITED:

I found a way for this problem I saved my connection strings on database for each user, after identification i will figure out which connection string is for this user, and then assign that to my data sources an etc ...

saved connection string

"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DB;Data Source=."

ASP

 <asp:SqlDataSource ID="DataSource" runat="server" ProviderName="System.Data.SqlClient </asp:SqlDataSource>

C#

DataSource.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DB;Data Source=.";

For Linq to SQL

DataClasses1DataContext m = new DataClasses1DataContext("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DB;Data Source=.");

i hope useful for other which has this issue

Upvotes: 0

Views: 577

Answers (1)

Andre Pena
Andre Pena

Reputation: 59336

In multi-tenant SaaS solutions it's very common to have multiple connection strings depending on the user tenancy or account.

You simply need to stop storing the connection string in the web.config file and start building them dynamically at runtime, preferably through a helper class, based on your criteria (logged user, account, tenancy...).

Upvotes: 1

Related Questions