.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
How do i set the connection string in my APP.XAML File
How do i set the connection string in my APP.XAML File
- 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
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 byJim Zhou - MSFTModeratorFriday, November 13, 2009 7:49 AM
- Unmarked As Answer byEhioze Monday, November 16, 2009 10:44 PM
- Marked As Answer byEhioze Monday, November 16, 2009 11:21 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 byJim Zhou - MSFTModeratorFriday, November 13, 2009 7:49 AM
- Unmarked As Answer byEhioze Monday, November 16, 2009 10:45 PM
- Marked As Answer byEhioze Monday, November 16, 2009 11:22 PM
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 bycodingsense Friday, November 13, 2009 8:56 AM
- 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 byJim Zhou - MSFTModeratorFriday, November 13, 2009 7:49 AM
- Unmarked As Answer byEhioze Monday, November 16, 2009 10:44 PM
- Marked As Answer byEhioze Monday, November 16, 2009 11:21 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 byJim Zhou - MSFTModeratorFriday, November 13, 2009 7:49 AM
- Unmarked As Answer byEhioze Monday, November 16, 2009 10:45 PM
- Marked As Answer byEhioze Monday, November 16, 2009 11:22 PM
- thanks a lot guys.
Acutally, i bought a book shortly after and it confirms what you said.
Ehi


