locked
How do i set the connection string in my APP.XAML File RRS feed

  • Question

  • Hello Guys,
    how do i set my connection string for my database in my APP.XAML file in my WPF project ?

    am using C#

    Thanks
    Ehi
    Friday, November 6, 2009 8:11 PM

Answers

  • Hi Ehioze,

    as Codingsense pointed out, it makes much more sense to store a ConnectionString - it's a per-user setting for most of all cases, hence it needs to be changeable.
    Double-click the Properties -node in your SolutionExplorer, go to the Settings Tab and enter a name in the Name column; choose (ConnectionString) as the Type , and - depending on whether your ConnectionString is to be fixed or not, choose Application or User for Scope . From your code, you can then - assuming you named your setting "myConnectionString" - obtain the setting like this:

    strConnectionString = Properties.Settings.Default.myConnectionString;


    Cheers,
    Olaf
    • Marked as answer by Jim Zhou - MSFT Friday, November 13, 2009 7:49 AM
    • Unmarked as answer by Ehioze Monday, November 16, 2009 10:44 PM
    • Marked as answer by Ehioze Monday, November 16, 2009 11:21 PM
    Thursday, November 12, 2009 3:45 PM
  • Hi Ehioze,

    In addition to Olaf Rabbachin's solution, you can also utilize the Application.Current.Properties to save the connection string:
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e5ae2b18-0795-49e8-a274-c3d52eccb8b3

    Thanks.
    Sincerely.

    Jim Zhou -MSFT
    • Marked as answer by Jim Zhou - MSFT Friday, November 13, 2009 7:49 AM
    • Unmarked as answer by Ehioze Monday, November 16, 2009 10:45 PM
    • Marked as answer by Ehioze Monday, November 16, 2009 11:22 PM
    Friday, November 13, 2009 7:48 AM

All replies

  • Hi Ehi,

    Is there any specific reason to have the connection string for your database in App.XAML file?
    You can also have it in App.Config file.

    Thanks,
    Codingsense
    • Proposed as answer by codingsense Friday, November 13, 2009 8:56 AM
    Thursday, November 12, 2009 12:11 PM
  • Hi Ehioze,

    as Codingsense pointed out, it makes much more sense to store a ConnectionString - it's a per-user setting for most of all cases, hence it needs to be changeable.
    Double-click the Properties -node in your SolutionExplorer, go to the Settings Tab and enter a name in the Name column; choose (ConnectionString) as the Type , and - depending on whether your ConnectionString is to be fixed or not, choose Application or User for Scope . From your code, you can then - assuming you named your setting "myConnectionString" - obtain the setting like this:

    strConnectionString = Properties.Settings.Default.myConnectionString;


    Cheers,
    Olaf
    • Marked as answer by Jim Zhou - MSFT Friday, November 13, 2009 7:49 AM
    • Unmarked as answer by Ehioze Monday, November 16, 2009 10:44 PM
    • Marked as answer by Ehioze Monday, November 16, 2009 11:21 PM
    Thursday, November 12, 2009 3:45 PM
  • Hi Ehioze,

    In addition to Olaf Rabbachin's solution, you can also utilize the Application.Current.Properties to save the connection string:
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e5ae2b18-0795-49e8-a274-c3d52eccb8b3

    Thanks.
    Sincerely.

    Jim Zhou -MSFT
    • Marked as answer by Jim Zhou - MSFT Friday, November 13, 2009 7:49 AM
    • Unmarked as answer by Ehioze Monday, November 16, 2009 10:45 PM
    • Marked as answer by Ehioze Monday, November 16, 2009 11:22 PM
    Friday, November 13, 2009 7:48 AM
  • thanks a lot guys.

    Acutally, i bought a book shortly after and it confirms what you said.

    Ehi
    Tuesday, November 24, 2009 11:01 AM
  • Hi Ehioze,
    Very gald to see that our solutions works for your, if you are having any additional issues with this, please feel free to feed back.

    Thanks.
    Sincerely.

    Jim Zhou -MSFT
    Wednesday, November 25, 2009 7:49 AM