Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : No connection string in application config file... but there is one

I have the following error when I try to build my solution:

No connection string named 'TechnicalAnalyzerEntities' could be found in the application config file.

The thing is that :

1/ there is one :

<connectionStrings>
    <add name="TechnicalAnalyzerEntities" connectionString="metadata=res://*/Data.Database.TAdb.csdl|res://*/Data.Database.TAdb.ssdl|res://*/Data.Database.TAdb.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PSYKOTROPYK-PC\PSYKOTROPYK;initial catalog=TechnicalAnalyzer;persist security info=True;user id=***;password=***;network library=dbnmpntw;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

2/ there is just one project in my solution (I search and the same error seems to appear when people have one project with the connection string and a startup project without, well not my case)

3/ this error seems not to prevent my project to run, nor Entity Framework to access the data and bind it to my treeview.

Actually the only issue is that there is this error showing in my error list and the MainWindow.xaml file (where the error is referenced) that can't show properly the custom control that then needs this connection string ==> cannot create an instance of "TreeviewSelector". The thing is that the custom control xaml file (TreeviewSelector.xaml as you guessed) is properly shown in the xaml editor.

This is not a dramatic error that prevents me to go forward on my project, but it is annoying to have errors and not to be able to properly use the xaml editor.

N.B.: A few other point that may be of interest : 1/ I use Entity Framework 6.0 2/ The project is on my laptop and the database on my desktop 3/ Blend shows the same MainWindow.xaml error 4/ If I put a copy of my project on my desktop (so on the same system as my database) I have the same problem

like image 344
samuel guedon Avatar asked Jun 04 '15 21:06

samuel guedon


People also ask

How does JSON define connections string in appSettings?

To define the connection strings in appsettings. json it is important to specify it in the right section of the JSON structure. Now we can read it in our code by calling the GetConnectionString method in the Microsoft. Extensions.

Where do I put connection string in web config?

After opening the web. config file in application, add sample db connection in connectionStrings section like this: <connectionStrings>


Video Answer


1 Answers

I've been there and struggled with that exact issue.

The solution is to add Entity Framework 6 to your application using NuGet. This will auto generate the correct connection string for you, and automatically set up your app.config perfectly.

The NuGet wizard that sets up app.config is quite smart: if there are some bad settings in it already, it will remove them and add good entries.

See my answer here: Upgrade from Entity Framework 5 to 6.

like image 53
Contango Avatar answered Sep 22 '22 09:09

Contango