SQL SERVER Name

AOA

Hello Every body hope u all are fine

My Question is simple hoe can i dynamically pick the sql server name in connection string

Thankx
LVL 2
Mohammad Aamir QureshiAsked:
Who is Participating?
 
2266180Connect With a Mentor Commented:
oh, understand now:
soemthing like this should do it then:
string connectionString = "Data Source="+System.Net.Dns.GetHostName()+"; Initial Catalog=NBP; Integrated security=SSPI;";

you might also want to check this: http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21609961.html
0
 
2266180Commented:
well, that depends on your implementation:

you create a new connection like new SqlConnection(constring);

and you construct constring as you wish :) (from UI, from a configuration fiel, etc)
0
 
Mohammad Aamir QureshiAuthor Commented:
AOA

Thankx for ur quick response

i want to pick dunamically sql server name in my SQL COnnection

thankx
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
adatheladCommented:
Hi ciuly,

When you say pick dynamically, how? - Do you want to type in the server name in your front end that you want to use, do you want a dropdown list of servers to choose from (if so, do you have this list defined somewhere)?

0
 
adatheladCommented:
Should have said "hi Aamirg", not  "Hi ciuly" :)
0
 
Mohammad Aamir QureshiAuthor Commented:
i think there is still comfusing is my question may b i cant explain

Explanation of Question

the Connection string is

string connectionString = "Data Source=TMANAGER; Initial Catalog=NBP; Integrated security=SSPI;";

Here the Datasource is our Computer as well as SQL SERVER 2000 name

i want to pick dynamically in my connectionstring through coding in C# because every computer have different server name

i think this is enough

Thankx
0
 
Mohammad Aamir QureshiAuthor Commented:
AOA

thank u ciuly

this code is exact what i want

once again thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.