Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > dynamic connection string?

Reply
Thread Tools

dynamic connection string?

 
 
kb
Guest
Posts: n/a
 
      03-04-2005
ASP.NET C#

how can i set this up:

i have a login page

if i login as clientA then i want to use clientA database
if i login as clientB then i want to use clientB database

both databases are on the same sql server, iam thinking could i have a dynamic connection sting in the web.config or somewhere else? so i would have something like this:

Persist Security Info=False;Data Source=local;Initial Catalog= + databaseNameGoesHere +;User ID=user;Password=pwd

any suggestions would be much appriciated

thanks
kb

 
Reply With Quote
 
 
 
 
MasterGaurav
Guest
Posts: n/a
 
      03-05-2005
Make connection string as:

connectionStringKey = ... Initial Catalog = {0}; user=....

When you want to use connection string:

string connString = String.Format(connectionStringKey, database_name);

--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
----------------------

 
Reply With Quote
 
 
 
 
Johnpc
Guest
Posts: n/a
 
      03-05-2005
You could maintain a server side xml file for your user like

<users>
<user name='[username]'><sqldb>[dbname]</sqldb></user>
</users>

and return the db name for the user when an as needed using

dbname = xml.selectSingleNode("users/user/[. =
'[username]']/sqlbd").nodeTypedvalue '!?chech my xpath for correctness

and insert it into your connection string

Persist Security Info=False;Data Source=local;Initial Catalog= + dbname
+;User ID=user;Password=pwd


"kb" wrote:

> ASP.NET C#
>
> how can i set this up:
>
> i have a login page
>
> if i login as clientA then i want to use clientA database
> if i login as clientB then i want to use clientB database
>
> both databases are on the same sql server, iam thinking could i have a dynamic connection sting in the web.config or somewhere else? so i would have something like this:
>
> Persist Security Info=False;Data Source=local;Initial Catalog= + databaseNameGoesHere +;User ID=user;Password=pwd
>
> any suggestions would be much appriciated
>
> thanks
> kb
>

 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      03-06-2005
here's what the appSettings section of your web.config could look like:

<configuration>
<appSettings>
<add key="DSN" value="Server=(local);Database=DBName;UID=sa;PWD="/>
<add key="OtherConnectionString" value="Server=(local);Database=DBName2;UID=sa;PWD= "/>
</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string
easily without rebuilding the app or restarting IIS or anything, and the
change goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn as string
If User = UserA Then
sConn = ConfigurationSettings.AppSettings("DSN")
Else
sConn = ConfigurationSettings.AppSettings("OtherConnection String")
End If

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"kb" <> wrote in message news:%...
ASP.NET C#

how can i set this up:

i have a login page

if i login as clientA then i want to use clientA database
if i login as clientB then i want to use clientB database

both databases are on the same sql server, iam thinking could i have a dynamic connection sting in the web.config or somewhere else? so i would have something like this:

Persist Security Info=False;Data Source=local;Initial Catalog= + databaseNameGoesHere +;User ID=user;Password=pwd

any suggestions would be much appriciated

thanks
kb

 
Reply With Quote
 
quaester
Guest
Posts: n/a
 
      03-09-2005
It depends what you want to achieve, the solution suggested by others is
workable.

I've implemented my solution for this scenario by puting my connection
string in database and prior to login to my portal, all database access is
using a minimal rights account, which can execute only a few stored procedure
to get authenticated and retrieve the connection string. In this manner, your
connection string can be really "dynamic".

Another method that you may try out is to use the username and password
(some security stuff need to be taken care here) to login to the sql, if it
throws you out, you are not athorized. And in your sql, you need to setup
those accounts for the users (the logins in sql), and ofcourse, the default
database. That means you will no longer set the initial catalog in your
connection string, but keep the setting in your sql accounts management.

there's not really any right or wrong, or which is best, as it depends on
your architecture and how many users and also how the maintenance work you
would want.

"kb" wrote:

> ASP.NET C#
>
> how can i set this up:
>
> i have a login page
>
> if i login as clientA then i want to use clientA database
> if i login as clientB then i want to use clientB database
>
> both databases are on the same sql server, iam thinking could i have a dynamic connection sting in the web.config or somewhere else? so i would have something like this:
>
> Persist Security Info=False;Data Source=local;Initial Catalog= + databaseNameGoesHere +;User ID=user;Password=pwd
>
> any suggestions would be much appriciated
>
> thanks
> kb
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Variables? OR Dynamic Controls =?Utf-8?B?VGVyb3M=?= ASP .Net 1 08-10-2004 01:13 PM
Dynamic control on aspx page, dynamic location Chris Thunell ASP .Net 3 07-21-2004 04:52 PM
VPN between 2 Cisco routers (1 static, 1 dynamic) with access from stat --> dynamic over ISDN Hans-Peter Walter Cisco 3 01-21-2004 02:12 PM
Does Pix or cisco router support dynamic-to-dynamic IPSec VPN? c Cisco 2 01-13-2004 01:53 AM
Re: Dynamic Table with Dynamic LinkButtons Rick Glos ASP .Net 0 07-08-2003 01:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57