Skip to content
Advertisement

App.Config in a class library for data access from WPF and ASP.NET?

I’m trying to use SQL for the first time to store data in one of my projects, I’m using this tutorial as it makes the most sense to me, and to be honest I like the guys videos, and hate clicking on hundreds of bad videos before finding one I can learn from.

Anyway I’m making an app where I need to access and save to a SQL database I have made in MSSMS, I have a class library for logic, a data class library for data access, and a WPF interface (I also plan to add an ASP interface with less edit features, but adding Web API, its all for learning)

In the video to connect dapper the guy sets up a helper to get the connection string, but that is looking up an App.Config through configuration manager (which he says is baked in and you just need to add a reference, but it seems now is a NuGet package).

But I have no App.config anywhere, and I’ve never used that so I don’t know if I’m supposed to add it, will it do anything, where would I add it? Or do I do something completely different nowadays using .NET Core not .NET Framework.

Sorry long post and maybe not as clear as it should be but I’m struggling here at the first hurdle and Google seems to be useless on this one.

As a side note I’m also planning to save key value pairs from my objects (as Dictionary<string, string>), am I best just having a new table just for those and store the I’d of the object it was associated with, the key, and the value in their own columns?

Advertisement

Answer

I ended up just going to my UI Add > New Item > Application Configuration File, called App.config and using this code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <clear/>
        <add name="Thenameasusedinmyapp" connectionString="Server =.; Database = NameofDatabase; Trusted_Connection = True;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement