Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir
I want to make dynamic connection string. for this I need get dynamically

Data Source[Server Name ] Server Name .then Please Help me How would I do.
I already use System.Envoirnment.Machine but It's Not giving FullName

What I have tried:

I need get Dynamically "Server Name" Like

Data Source ="Server Name";Initial Catalog="Database Name" Integrated Security=True
Posted
Updated 25-Mar-20 16:12pm
v3
Comments
Richard MacCutchan 25-Mar-20 7:59am    
Your question is impossible to answer, as we have no idea what server you are referring to, or what you mean by "how would i get dynamic data server name". Please edit your question and add some proper details.

1 solution

Add a reference to System.Configuration and then you can read the connection strings from your web.config like such:
C#
System.Configuration.ConfigurationManager.ConnectionStrings["NameOfYourConnectionString"].ConnectionString;
 
Share this answer
 
Comments
satyanand mishra 25-Mar-20 22:01pm    
sir thank you for posting this answer but I want to get dynamic server name and instance of
sql server 2014 how would I do.
Dave Kreskowiak 26-Mar-20 0:38am    
Ask the user for the name of the server?

You could use SQL DMO to get all of the SQL Servers that are publicly visible on the network, but you still have to ask the user which one to use.

Google - sql dmo list servers[^]
ZurdoDev 26-Mar-20 7:06am    
Depends. Where is this "dynamic" server name coming from?

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