locked
Scope "Application" vs scope "User" RRS feed

  • Question

  • BH
    Hi, 
    I'm trying to create a setup screen where a user can change the connection string. However , I noticed, a setting with the scope "Application" is not saved when changed at runtime  (code below). is it not best practice to change connection string at runtime? How do I let the user control the connection string?

    properties.settings.default.save();

    Thanks

    Aron


    Thanks Aron www.EvidenceForTorah.comxa.com

    Monday, September 1, 2014 6:17 PM

Answers

  • Hi Aron,

    Scope "Application" vs scope "User"

    If Scope =Application, it is read only. This property cannot be assigned to.

    If Scope=User, can be written at run time, just as you would change any property value. The new value persists for the duration of the application session. You can persist changes to user settings between application sessions by calling the Settings.Save method.

    If you want additional recommendations on this:Using Settings in C#

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Kristin Xie Tuesday, September 9, 2014 8:46 AM
    Tuesday, September 2, 2014 7:42 AM
  • I wouldn't let the user control connection string at all.

    Not directly.

    They will break it.

    If you have some sort of form the user picks where their database is and you check it's there programmatically, check you can connect and then save a string which you generate...

    That could work.

    But never ever let the user just type a string in.

    They will f**k it up.

    .

    An explanation of why application settings save fails:

    From here:

    http://msdn.microsoft.com/en-us/library/bb397755(v=vs.110).aspx

    Notice:

    "

    Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.

    "


    Hope that helps
    Please don't forget to up vote answers you like or which help you and mark one(s) which answer your question.


    • Edited by Andy ONeill Tuesday, September 2, 2014 7:40 AM
    • Marked as answer by Kristin Xie Wednesday, September 10, 2014 1:49 AM
    Tuesday, September 2, 2014 7:37 AM

All replies

  • I wouldn't let the user control connection string at all.

    Not directly.

    They will break it.

    If you have some sort of form the user picks where their database is and you check it's there programmatically, check you can connect and then save a string which you generate...

    That could work.

    But never ever let the user just type a string in.

    They will f**k it up.

    .

    An explanation of why application settings save fails:

    From here:

    http://msdn.microsoft.com/en-us/library/bb397755(v=vs.110).aspx

    Notice:

    "

    Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value. The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.

    "


    Hope that helps
    Please don't forget to up vote answers you like or which help you and mark one(s) which answer your question.


    • Edited by Andy ONeill Tuesday, September 2, 2014 7:40 AM
    • Marked as answer by Kristin Xie Wednesday, September 10, 2014 1:49 AM
    Tuesday, September 2, 2014 7:37 AM
  • Hi Aron,

    Scope "Application" vs scope "User"

    If Scope =Application, it is read only. This property cannot be assigned to.

    If Scope=User, can be written at run time, just as you would change any property value. The new value persists for the duration of the application session. You can persist changes to user settings between application sessions by calling the Settings.Save method.

    If you want additional recommendations on this:Using Settings in C#

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Kristin Xie Tuesday, September 9, 2014 8:46 AM
    Tuesday, September 2, 2014 7:42 AM