Results 1 to 7 of 7

Thread: Web Config connection string

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    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"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Addicted Member Claude2005's Avatar
    Join Date
    Jan 2010
    Location
    Philippines
    Posts
    166

    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.
    If a post was helpful to you in any way, rate it. If your problem/question has already been solved/answered, remember to mark your thread as resolved.

    Useful Tools: C# to VB Converter
    Tutorial Sites: W3Schools|ASP.Net|ASP.Net QuickStart|LearnVisualStudio.Net

    So many things to learn, so little time... >_<

    Under Construction...

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    Re: Web Config connection string

    If I log in I want to point to the development environment...all others to production
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6
    Addicted Member Claude2005's Avatar
    Join Date
    Jan 2010
    Location
    Philippines
    Posts
    166

    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"
    If a post was helpful to you in any way, rate it. If your problem/question has already been solved/answered, remember to mark your thread as resolved.

    Useful Tools: C# to VB Converter
    Tutorial Sites: W3Schools|ASP.Net|ASP.Net QuickStart|LearnVisualStudio.Net

    So many things to learn, so little time... >_<

    Under Construction...

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width