[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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
0
Mohammad Aamir Qureshi
Asked:
Mohammad Aamir Qureshi
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
2266180Commented:
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
 
Mohammad Aamir QureshiAuthor Commented:
AOA

thank u ciuly

this code is exact what i want

once again thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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