XAML designer in WPF project throws error - no connection string named xxx could be found.

Kalpana 21 Reputation points
2022-08-15T08:51:55.27+00:00

Hi

I am trying to do a MVVM wpf project and I receive this error on the MainWindow. xaml view, the error is appearing on the user controls as well.

However, I am able to launch the exe.

Can someone assist me with this, I am using Visual Studio 2019 community edition, entity framework 6.4.4.
I think it is to do with my entity framework, but I really do not what is wrong here.
This is my connection string.

<add name="DBoneDBContext" connectionString="data source=DE21TOP-123G2C0\SQLEXPRESS;initial catalog=KAL_Local_Reasonsv1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
790 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 51,346 Reputation points
    2022-08-15T14:50:43.133+00:00

    My running theory is that in your XAML file or codebehind you are hooking up DataContext or creating an instance of one of your data classes. You are doing that by querying the DB. However your app's configuration files and therefore the DB are not available at design time and therefore it will fail.

    You should not do anything related to querying data or runtime stuff at design time. Basically that means your XAML code and constructors should not have any code that requires DB access. All this is executed in the designer sandbox and will fail. At design time use the designer data context to associate your data types (not instances) to get Intellisense. If you really need data then use a design-time only data instance.


0 additional answers

Sort by: Most helpful