Solved

How could you update the connection string automatically during an install

Posted on 2010-11-16
6
436 Views
Last Modified: 2012-05-10
What would be the best way to update a config file which contains a connection string to a SQL database  with the correct name of the machine.
i.e; Change line:
 <connectionStrings>
    <add name="DBConnectionString" connectionString="Data Source=ANY_LAPTOP\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

to

 <connectionStrings>
    <add name="DBConnectionString" connectionString="Data Source=MY_LAPTOP\SQLEXPRESS;Initial Catalog=DB1;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
0
Comment
Question by:Spike_66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:alaran
ID: 34147408
If you mean during install from an .msi package, you should look into "Custom Actions" for the installer project. These allow you to execute pretty much whatever you want during installation, including manipulating the .config file.

The connection string can then be asked for during installation and inserted into the config file during installation.

Post number two here has a sample: http://stackoverflow.com/questions/918565/updating-appname-config-file-from-an-custom-installer-class-action
0
 

Author Comment

by:Spike_66
ID: 34147583
This is good but the user is unlikely to know the connection string.
This would be for an application connecting to an existing application on a SQL server database.
0
 
LVL 4

Expert Comment

by:alaran
ID: 34147636
The custom action can also get the connection string from another place if that is possible. (like web service, file, system information or whatnot)
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34150444
Is it just the server name that would be dynamic or the instance name and db name as well? Is the server expected to be local or network?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 34150452
If its always the local computer then you can use

".\SQLExpress" instead of "computername\SQLExpress" in the connectionstring.
0
 

Author Closing Comment

by:Spike_66
ID: 34154193
Simple!
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question