Web Config connection string
Can you use a session variable in a web config connection string? So instead of:
Code:
<add name="ConnectionString2" connectionString="Data Source=ora;Persist Security Info=True;User ID=SA;Password=PASS;Unicode=True"
something like this:
Code:
<add name="ConnectionString2" connectionString="Data Source=" & Session(DB) & ";Persist Security Info=True;User ID=SPAR;Password=;Unicode=True"
Re: Web Config connection string
Hi there,
I believe the answer is no, since the DataSource part refers to the name of your database. And it's not practical, imo, for each user to have his/her own database for your web app.
Re: Web Config connection string
Agreed.
EyeTallion, what is the reason that you are trying to do this? Typically, the Data Source, i.e. the name of the database is set on a per application basis, not on a per user basis.
Gary
Re: Web Config connection string
If I log in I want to point to the development environment...all others to production
Re: Web Config connection string
Interesting.
Why not simply have another instance of the site, either on another domain, or as a subdomain, and point that instance at the development DB?
Gary
Re: Web Config connection string
How about this? It's in SQL. I don't know how to do it in Oracle...
Code:
Dim cmd As New SqlCommand
If <admin> Then
cmd.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("AdminConnectionString").ConnectionString)
Else
cmd.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("UserConnectionString").ConnectionString)
End If
Code:
<add name="AdminConnectionString" connectionString="Data Source=ora_admin;Persist Security Info=True;User ID=SA;Password=PASS;Unicode=True"
<add name="UserConnectionString" connectionString="Data Source=ora_user;Persist Security Info=True;User ID=SA;Password=PASS;Unicode=True"
Re: Web Config connection string
Hey,
Yes, this approach will work, if you are always creating the connections to the Database in Code. If you are using some of the built in controls though, this will not work so well.
The technique would be exactly the same in Oracle, just that you would be using an OracleConnection, rather than a SqlConnection.
Gary