How to get connection string from another project in LINQ to SQL?

I have 3 different projects in one solution. I put the connection string in the first project like this

<connectionString name="My Connection String"> <parameters> <parameter name="Integrated Security" value="True" /> <parameter name="server" value=".\SQLEXPRESS" isSensitive="true" /> <parameter name="database" value="MyDatabase" isSensitive="false" /> </parameters> </connectionString> 

Now in another project, I'm doing a LINQ to SQL class, and it generated the app.config file and injected a connection string into it? How can I do to read the connection string from my existing .config file from another project?

+1
source share
1 answer

I assume that you are using application settings and have a connection string in FirstProject .

Like this:

enter image description here

The generated settings class is marked with internal sealed partial .. , so you cannot access it directly through MyProject.Properties.Settings..

You simply create a class to display it:

 namespace FirstProject { public class ThisProjectSettings { public static string ConnectionString { get { return Settings.Default.Conn; } } } } 

Then use it from your second project as follows:

 FirstProject.ThisProjectSettings.ConnectionString 
+4
source

Source: https://habr.com/ru/post/1400164/


All Articles