Login based connection string setting!

G

Guest

Hi!

I am developing a VB .NET based app for a company X that has five associate
companies A,B,C,D, and E. Each of the associate companies has its own
database, but have one common database to store the user profile and login
details. All the five databases are identical.

I have one application for all the companies. My app uses several hard coded
sqldataAdapters and DataSets that retrieve their connection string from
Web.config file. Now I am have to replicate this app for all the five
companies, and I am wondering how to set the connection string
dynamically/programmatically based on the login of a user?

I assume Web.config file sets application wide variables....correct me if I
am wrong!! Is there is Web.config equivalent for a session?

Would appreciate an early response.

Thanks
 
G

Guest

My suggestion:

1. Make a global routine that gets connection string for the session

public string GetConnectionString(string userName)
{
}

2. Set up multiple strings, either in a "metadata" database, or in the
web.config. Easy enough to make multiple keys, like:

<appSettings>
<add key="CompanyAConnString" value ="" />
<add key="CompanyBConnString" value ="" />
<add key="CompanyCConnString" value ="" />
<add key="CompanyDConnString" value ="" />
<add key="CompanyEConnString" value ="" />
</appSettings>

The conn string is set once a session and used throughout. Fairly simple.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
S

Sahil Malik

Actually I'd like to twist that idea a bit.

Represent your connection strings as a class that holds a collection of
connection strings.
XML Serialize that file - save it to a file other than anything to do with
Web.Config.
On session start, throw it in the cache, set a filedependency, so whenever
the file that stores your conn-strings changes, this class automatically
gets updated.

Advantages -
1. The appdomain doesnt' restart when you have to modify a conn-string.
2. You are not limited to the number of conn-strs.
3. You don't have method jumps to get a conn-str.
4. You can access the connstrs via a static class "globals.connstrs[A]" ..
blah blah.

Just a better design IMO :)

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
 
G

Guest

Hi Sahil Malik,

Thanks for the response. I would like to know more about your solution with
a code example. Thanks for your time.

Sahil Malik said:
Actually I'd like to twist that idea a bit.

Represent your connection strings as a class that holds a collection of
connection strings.
XML Serialize that file - save it to a file other than anything to do with
Web.Config.
On session start, throw it in the cache, set a filedependency, so whenever
the file that stores your conn-strings changes, this class automatically
gets updated.

Advantages -
1. The appdomain doesnt' restart when you have to modify a conn-string.
2. You are not limited to the number of conn-strs.
3. You don't have method jumps to get a conn-str.
4. You can access the connstrs via a static class "globals.connstrs[A]" ..
blah blah.

Just a better design IMO :)

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/



Cowboy (Gregory A. Beamer) - MVP said:
My suggestion:

1. Make a global routine that gets connection string for the session

public string GetConnectionString(string userName)
{
}

2. Set up multiple strings, either in a "metadata" database, or in the
web.config. Easy enough to make multiple keys, like:

<appSettings>
<add key="CompanyAConnString" value ="" />
<add key="CompanyBConnString" value ="" />
<add key="CompanyCConnString" value ="" />
<add key="CompanyDConnString" value ="" />
<add key="CompanyEConnString" value ="" />
</appSettings>

The conn string is set once a session and used throughout. Fairly simple.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
S

Sahil Malik

Hey Raj,

Just look at the System.Xml.Serialization.XmlSerializer class. That has good
code examples.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/


Raj said:
Hi Sahil Malik,

Thanks for the response. I would like to know more about your solution
with
a code example. Thanks for your time.

Sahil Malik said:
Actually I'd like to twist that idea a bit.

Represent your connection strings as a class that holds a collection of
connection strings.
XML Serialize that file - save it to a file other than anything to do
with
Web.Config.
On session start, throw it in the cache, set a filedependency, so
whenever
the file that stores your conn-strings changes, this class automatically
gets updated.

Advantages -
1. The appdomain doesnt' restart when you have to modify a conn-string.
2. You are not limited to the number of conn-strs.
3. You don't have method jumps to get a conn-str.
4. You can access the connstrs via a static class "globals.connstrs[A]"
..
blah blah.

Just a better design IMO :)

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/



"Cowboy (Gregory A. Beamer) - MVP" <[email protected]>
wrote
in message news:D[email protected]...
My suggestion:

1. Make a global routine that gets connection string for the session

public string GetConnectionString(string userName)
{
}

2. Set up multiple strings, either in a "metadata" database, or in the
web.config. Easy enough to make multiple keys, like:

<appSettings>
<add key="CompanyAConnString" value ="" />
<add key="CompanyBConnString" value ="" />
<add key="CompanyCConnString" value ="" />
<add key="CompanyDConnString" value ="" />
<add key="CompanyEConnString" value ="" />
</appSettings>

The conn string is set once a session and used throughout. Fairly
simple.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

:

Hi!

I am developing a VB .NET based app for a company X that has five
associate
companies A,B,C,D, and E. Each of the associate companies has its own
database, but have one common database to store the user profile and
login
details. All the five databases are identical.

I have one application for all the companies. My app uses several hard
coded
sqldataAdapters and DataSets that retrieve their connection string
from
Web.config file. Now I am have to replicate this app for all the five
companies, and I am wondering how to set the connection string
dynamically/programmatically based on the login of a user?

I assume Web.config file sets application wide variables....correct me
if
I
am wrong!! Is there is Web.config equivalent for a session?

Would appreciate an early response.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top