5

I would like to know is there any way to declare a variable in setting.setting file to hold my connection string. then i can read it from there for example:
properties.settings.default.connectionstring

thanks

3
  • 1
    Any reason the connectionStrings section in the .config file is not good enough? Commented Sep 2, 2011 at 20:04
  • Just wanted to find out if it possible. coz it does not accent initialcatalog variable in there. Commented Sep 3, 2011 at 16:14
  • 1
    You can escape characters within the .config file. Commented Sep 3, 2011 at 17:45

2 Answers 2

1

Add the setting in the Settings tab in the properties of your project. Make sure it's User scope, not Application scope or it will be read only. Then access it using Settings.Default.ConnectionString

Just keep in mind that this isn't "secure" if that is your goal. Just makes it easier to change at runtime vs a config file. Note that the settings are actually stored in the config file.

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

Comments

0

Is there a problem using the recommended (web/app).config to hold connection strings?

How to: Read Connection Strings from the .config File

Comments

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.