Solved

connection string dynamic server value

Posted on 2011-03-08
5
228 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
For which DBMS?
0
 

Author Comment

by:mkarthik415
Comment Utility
We are using Sql Server 2008.
0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now