1

Keeping of MySql connection string with server, user, password and database data seems incorrect inside the code.

I see only two ways, how it can be stored, one is adding into Resources .txt like string data = Properties.Resources.doc;, but I'm not sure if it is secured method, another must be .xml, but I can't find any good guide, how to created such kind of access with .xml correctly, and I'm also not sure if it is most proper way.

Any advice, guide or example would be useful

0

1 Answer 1

3

The standard way to store a connection string in a WinForms application is creating an entry in the connectionStrings section inside the app.Config file.

<configuration>
    <connectionStrings>
         <add name="MyConnection" connectionString="Server=myServer;Database=myDatabase;
                                                    userid=root;password=pass;Port=3306"/>
    </connectionStrings>
    .....
</configuration>

Now you can retrieve this connection string in your code referencing the key named MyConnection using code like this:

string cnnString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

It is up to you to decide if you want to retrieve this info every time you need it or store it inside some kind of ad hoc in memory structure like a static MyAppConfig class

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

1 Comment

Hello, exactly what I was looking for, great support

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.