Hi everyone,
I'm n00wbie to C# and I I have one question.
I'm writting class for access to MySQL over DbLinq and I need to know connection string. I know that I can read connection string from webconfig file. My question is is there any function in C# that I can use during runtime to get answer for connection string independent of that I'm executing web application or desktop application (read from appconfig) ????

Recommended Answers

All 3 Replies

I'm not sure I get the nature of the question.

You can certainly use the exact same code to retrieve the connection string in either a desktop or web scenario. ConfigurationManager.ConnectionStrings["name_here"].ConnectionString will retrieve the information you need, whether it be in web or app.config. You will probably need to update your reference to System.Configuration in the project, however.

I imported using System.Configuration;
but there is one error in desktop
Error 1 The name 'ConfigurationManager' does not exist in the current context C:\Users\dominum\Documents\Visual Studio 2008\Projects\WindowsFormsApplication6\WindowsFormsApplication6\Form1.cs 22 39 WindowsFormsApplication6

That's why I said you need to set a reference.

From Solution Explorer, right click on References and select Add Reference. Scroll down and select System.Configuration.

From the menu bar, you can go to Project -> Add Reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.