blah blah blah is here! blah blah » Close

up0down
link

Hi

In asp.net you can easily put the connectionstring to your database in webconfig file and use configurationmanager to reach it from different pages.
Is there a similair way in win form applications? Let say I create a class and call it Connections and from every form I create I can reach the connectionstring?
In that case if I change database I do not need to change the connectionstring on every form, only in the class.
Thank you.

last answered one year ago

1 answers

up0down
link

Yes, you could do it like that by creating a static class which is visible to all other classes in the application:

// VS 2008 or later assumed

internal static class Connections
{
internal static string ConnectionString {get; set;}
}

// set it with:
Connections.ConnectionString = "whatever";

// get it with:
string connStr = Connections.ConnectionString;

Thank you Vulpes, sorry forgot to say VS2008, exactly what I was looking for.

Feedback