Solved

How could you update the connection string automatically during an install

Posted on 2010-11-16
6
431 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:alaran
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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
Comment Utility
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
Comment Utility
Simple!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now