Thank you for posting in the MSDN forum.
Based on your description, I’m afraid that it is not the correct forum for this issue, since this forum is to discuss:
Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, Visual Studio Report Controls, and Visual Studio Editor.
To help you find the correct forum for this issue, would you mind letting us know more information about this issue? Which language are you using? Which kind of app are you developing, the Asp.net app or others? If it is related to the ASP.net, you could post this issue to http://forums.asp.net where asp.net experts live in.
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
A connection string is a STRING and you can set the connection string like any other string variable. There are many different methods that use connection strings so it is hard to give any sample code without knowing exactly what method you are using.
Thanks for reply,
Actually I am developing a website using ASP.NET with C# under VS 2010.
I have developed a database using SQL Server 2008 R2.
I wanted a way to determine connection string through coding without getting it through property window, so that when I deploy my website on client side, I don't have a again modify it using VS.
Is anything like that possible?
Below is my connection string for a SQL Server 2008 R2 database. We have the same database on multiple PCs. The comboxbox will fill in the Server name. Now if it is always on the PC where the application is running you could use LocalHost, or get the PC name using Dns.GetHostName();
strCon = "Data Source=" + comboBox1.Text + "\\SQLEXPRESS;Initial Catalog=ABC;Integrated Security=SSPI";
You could have a menu option to add the server name. Sometimes I like to have an invisible text box and store config info in the invisible box. Another possiblilty is to load thje connection string into Control Panel - Admin tools - Data Sources (ODBC).