Solved

How could you update the connection string automatically during an install

Posted on 2010-11-16
6
437 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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