Solved

connection string dynamic server value

Posted on 2011-03-08
5
230 Views
Last Modified: 2012-06-21
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
Comment
Question by:mkarthik415
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35075999
For which DBMS?
0
 

Author Comment

by:mkarthik415
ID: 35079857
We are using Sql Server 2008.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35080371
Data Source in the connection refers to the server. So you want to point people to different database servers based on "userType"?
0
 
LVL 8

Accepted Solution

by:
Anurag Agarwal earned 500 total points
ID: 35081385
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
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35081419
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question