Avatar of mkarthik415
mkarthik415
 asked on

connection string dynamic server value

Hi

Below is the connection string to my database.
Depending on the user provided value(suppose it as "userType"), the "data source" value "SERVERNAME" is changed ie depending on userType, the user is connected to database.

connectionString="Initial Catalog=IC1;Application Name=AN1;data source={SERVERNAME};User ID=xxx;password=xxx;"

Do any one has sample/ suggestion or links similar to this one. I am confused how "SERVERNAME" and "userType" are related to each other.

Thank You
C#.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Anurag Agarwal

8/22/2022 - Mon
kaufmed

For which DBMS?
mkarthik415

ASKER
We are using Sql Server 2008.
Carl Tawn

Data Source in the connection refers to the server. So you want to point people to different database servers based on "userType"?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Anurag Agarwal

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Anurag Agarwal

Function GetConnectionString() As String
        Dim Datasource As String = Txt_SqlSrvrName.Text
        Dim Catalog As String = txtCatalog.Text
        Dim userid As String = Txt_userID.Text
        Dim Pwd As String = txt_Pwd.Text

        Dim SMS_DistrictConn As String = "Data Source=" & Datasource & ";Initial Catalog=" & Catalog & ";Persist Security Info=True;User ID=sa;Password=" & Pwd & ";"

        Return SMS_DistrictConn
    End Function


do something like this and save the connection string in viewstate