• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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
0
mkarthik415
Asked:
mkarthik415
1 Solution
 
käµfm³d 👽Commented:
For which DBMS?
0
 
mkarthik415Author Commented:
We are using Sql Server 2008.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Data Source in the connection refers to the server. So you want to point people to different database servers based on "userType"?
0
 
Anurag AgarwalCommented:
mkarthik415 no need to get confuse get the basic idea

"SERVERNAME"  : is the instance name of the sql server for which it is installed which Generally is installed by default with the IP address of the system or along with a instance name say for eg
u have lan ip as 192.10.5.20 , and sql server 2008 is installed with default instance name then your servername for sql server will be 192.10.5.20 (or . which means local server) if u have instance name along with say mkarthik415_SQLServer then "SERVERNAME will be 192.10.5.20\mkarthik415_SQLServer (or .\mkarthik415_SQLServer as local )

and "userType" is the user created for the particular databse like each database has default userid as sa you can also create userid for your db.

The  "SERVERNAME" and "userType" are related to each other in the manner that in connection string first u mention that which DB Server u are connecting , Second thing u need to mention Catalog is which database u r connecting and thirdly through which user u r connecting to that database.

User are  created as stating how much accessing, deleting or using rights are given to user for a database as sa user is administrator and u may not give all rights to all db users
0
 
Anurag AgarwalCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now