Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I edit an Entity Framework connection string?

I recently had to edit my app.config file to change the connection string for an Entity Framework data model (.edmx file). But I'd like to know: Is there a way to edit the EF connection string using the designer?

The original connection string is auto-generated by the Entity Data Model wizard. The connection string then cannot be changed - it remains disabled in the properties window of the .edmx designer. I like to avoid editing XML by hand if I can (in app.config), so I was wondering if there is a way to get back into the original wizard screen to make connection string changes and let the tool edit the app.config file for me.

like image 323
DeveloperDan Avatar asked Oct 05 '22 21:10

DeveloperDan


People also ask

How do I change the connection string after deployment?

If you save your connection string in the udl file, the user can change the connection via an interface by simply double clicking that file. You can set your connection string in the app to point to the udl file. You can also launch the udl interface programmatically if you want.

What is good way to declare a connection string?

You need to use the connectionStrings tag to specify the connection string in the web. config file as in the following image. Write this XML markup in the web config file for declaration of the connection. You can add many tags for each database connection.


2 Answers

If you remove the connection string from the app.config file, re-running the entity Data Model wizard will guide you to build a new connection.

like image 146
Fabian Nicollier Avatar answered Oct 20 '22 09:10

Fabian Nicollier


No, you can't edit the connection string in the designer. The connection string is not part of the EDMX file it is just referenced value from the configuration file and probably because of that it is just readonly in the properties window.

Modifying configuration file is common task because you sometimes wants to make change without rebuilding the application. That is the reason why configuration files exist.

like image 37
Ladislav Mrnka Avatar answered Oct 20 '22 09:10

Ladislav Mrnka