0

I am making a line of Windows Forms applications. I am building the functionality of an options menu using the application settings tools to keep persistent data and settings. In addition, all applications will allow the user to connect to a database and query data. I am trying to find out a way to put a databse section in the options to allow the user to test and set database options. When set I want the same settings to show up or sync with another application at runtime or when the next time another app is opened.

So far I have been thinking about using the windows registry, or making a project with application settings and adding it to all applications. I also read about using a machine config file. I am not too sure on what is the best or how this would all work when the applications are deployed.

The sharing of settings and/or values is not limited to just a connection string, but any data that may be useful to keep concurrent with all applications.

2 Answers 2

1

You can open config files from any place with the ConfigurationManager. With this you can define a central configuration in a directory known to all your applications. See MSDN.

Sign up to request clarification or add additional context in comments.

1 Comment

I was going to suggest this approach, as well. I would add that you should consider IsolatedStorage for the location of your "global" config file. Ref: msdn.microsoft.com/en-us/library/vstudio/…
0

In this case I use SqlServer express, the best free DataBase. In the App.config add this code

    <connectionStrings>
        <add name="MyConnection" connectionString="User ID=sa;Password=XXXXX;Initial Catalog=DATA_BASE_NAME;Data Source=XXXX\SQLEXPRESS"/>
</connectionStrings>

In a Static Class of your application add this method

public static SqlConnection getConnection()
        {
            string conn = string.Empty;
            conn = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
            SqlConnection aConnection = new SqlConnection(conn);
            return aConnection;
        }

When you have need of db connection you call method in this way

SqlConnection aConnection = getConnection();

4 Comments

Ok. Let's say I change this connection string at runtime. In addition, other applications are going to use this connection string to connect to the same database. Now, how can I manage to let other applications see or get this newly changed connection string?
At runtime you can use this strategy for change connectionstring: SqlConnection aConnection = new SqlConnection("name=MyDataBase connectionString=User ID=sa;Password=XXXXX;Initial Catalog=DATA_BASE_NAME;Data Source=XXXXX\\SQLEXPRESS");
I understand that as well. I know I can build and assign the connection string at runtime. My dilemma is when I need to save and allow that connection string to be seen by another application to be used to connect to a database.
In this case I think can you save file in registry or in another file of your system and read this COnnectionString when have you need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.