Posts

Showing posts with the label app configuration

Entity Framework/Entity Framework Core connection strings for Windows Forms

Image
When creating a DbContext for Entity Framework 6 or Entity Framework Core by default the constructor for Entity Framework 6 has the name for the connection string and for Entity Framework Core is embedded in OnConfigurating. For personal usage and this is fine while in professional applications there are two considerations, first can someone use the connection string maliciously to gain access to data and secondly, developers should have separate environments for testing. In the following repository there are code samples for encrypting/decrypting connection strings and code samples for working with development, staging and production environments. Each project has a readme file which explains how to implement in a project. Although the majority of code samples are C# using Entity Framework Core there is an example for C# Entity Framework 6 and one example for Entity Framework Core with VB.NET along with unit test. Running code samples Using SSMS (SQL-Server Management Studio), create...

Get/Set app.config values for WPF and Windows forms using C#

Image
In Windows forms developers sometimes need a place to store information like connection strings or data binding to controls. This is typically done usually under project properties by creating a setting which generates xml e.g. < userSettings >   < WindowsFormsApp1.Properties.Settings >     < setting   name = " Author "   serializeAs = " String " >       < value > Karen Payne </ value >     </ setting >   </ WindowsFormsApp1.Properties.Settings > </ userSettings > Although this works sometimes we want more control so we can have < appSettings >   < add   key = " DatabaseServer "   value = " .\SQLEXPRESS "  />   < add   key = " Catalog "   value = " NorthWind2020 "  />   < add   key = " SortColumn "   value = " CompanyName "  />...