Click here to Skip to main content
15,672,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am using sql server 2000 , with asp.net2.0 with c#

In my client machine how to read the Data Source value from client system
user id , password ,database name is same for all clients but how to get Data Source value in connection string .
can you give example which helps me.

Thanks in Advance.
Updated 22-Apr-18 22:25pm
mcapatna 7-Jul-10 7:22am    
will you please elaborate your question with any example
Sandeep Mewara 7-Jul-10 8:16am    
Do you want to get the datasource value or assign it? Connection string already defined? You need access in code?

A better way:

return new SqlConnectionStringBuilder(Settings.Default.OperatorsConnectionString).DataSource;
Share this answer
If you already have the connection string, just split the string like so:

string[] parts = connectionString.Split(';');

and then iterate through the parts array until you find the part that starts with "Data Source=".

string dataSource = "";
for (int i =0; i < parts.Length; i++)
    string part = parts[i].Trim();
    if (part.StartsWith("Data Source="))
        dataSource = part.Replace("Data Source=", "");

It ain't rocket science...
Share this answer
[no name] 28-Jun-11 3:37am    
Good Call JSOP.My 5 too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900