Entity Framework/Entity Framework Core connection strings for Windows Forms

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 and populate the database using North2020Script.sql.
  • Right click on Solution Explorer, select restore NuGet packages.
  • Build the solution.
  • Open test explorer window.
  • Select run all test.

Summary

By inspecting code provided in the following GitHub repository you have options to setup connection strings for Entity Framework 6 and Entity Framework Core for Windows Forms which will also work in WPF projects.

Notes 

  • Code for encryption and decryption methods and variables have names that are not expected which is one more diversion to get back from hackers. 
  • That all C# code was reversed engineered using EF Power Tools.

Comments

Popular posts from this blog

VB.NET Working with Delegate and Events

Coders asking questions in online forums

GitHub download partial repository