Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Access a connectionstring from another project

I got two project in my solution in Visual Studio 2010.
Project 1 contains an app.config with a ConnectionString.

How can I access that ConnectionString from Project 2?

Since they are both using the same ConnectionString, I would prefer to only have one instance in my solution.

like image 648
gulbaek Avatar asked Jun 06 '11 08:06

gulbaek


People also ask

How do you read connectionString from configuration file into code behind?

To read the connection string into your code, use the ConfigurationManager class. string connStr = ConfigurationManager. ConnectionStrings["myConnectionString"].

Where are connectionStrings stored?

Connection strings can be stored as key/value pairs in the connectionStrings section of the configuration element of an application configuration file.


1 Answers

You can add the files as a link to the file to one of your projects.

Use Add an Existing Item to the project you want to add the file to - the Open button has a small down arrow, if you click that you can select Add as Link.

This will add the file as a link from the original location, meaning you only have one physical file.

like image 168
Oded Avatar answered Oct 26 '22 12:10

Oded