3

i would like some help with a program i am developing, i want the user to be able to set the database connection string from a form i have developed. I have seen many articles on this, including many answers on stack overflow that all worked but none of them permanently write the connection to the app.config file, meaning when the application is closed the connection string retains it's former value (during debugging), i want to know if there is a way i can solve this issue.

I have already tried this: How can i update app.config connectionstring Datasource value in C#?

And this is what i am currently using:

http://www.codeproject.com/Questions/388444/How-change-connection-string-dynamically-in-csharp See Solution 2

8
  • 2
    Try following answer: stackoverflow.com/a/1357453/1661209 Commented Feb 20, 2014 at 11:24
  • 2
    if this issue is for debugging only then it is because configuration file is updated when you build your project, and this issue will be no more when you deploy it. Commented Feb 20, 2014 at 11:26
  • You will need to rewrite the configuration file, and restart the app. Commented Feb 20, 2014 at 11:28
  • @Milan Raval Interesting, so are you then suggesting that when the application is packaged and deployed unto the client's machine once he sets the connection string once it will NOT change again even if he restarts the application? Commented Feb 20, 2014 at 11:30
  • 1
    One problem with trying to change the app.config is that you might not have the permission to do so if the application is installed in a protected folder like Program Files. Commented Feb 20, 2014 at 11:37

1 Answer 1

1

Assuming this is a Forms/Console application called WindowsFormsApplication1:

When running your application in Visual Studio in Debug mode, the file that will be updated is:

bin\Debug\WindowsFormsApplication1.vshost.exe.Config

Each time you terminate your debugging session this file will then revert back to whatever is contained in your project's app.config file.

There are reasons for this behaviour which I don't have time to explain right now.

When you run your application standalone i.e. not within Visual Studio then the app.config file deployed with your app binaries will be the file that gets updated.

For example, I copied the output of my bin\Release folder (excluding any *.vshost.* files) to another directory outside the project structure, launched the app and sure enough my config changes do get saved to app.config.

Sign up to request clarification or add additional context in comments.

2 Comments

Oho!! Thanks i get it now, so i can't really permanently update the settings in my projects app.config file during debug mode then.
That seems to be the case. In my head I understand why, but right at this moment don't have time to explain it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.