Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm developing with mysql database.

I always declared the details about the database I use at the top of every form. I mean, the database name,username,password and everything about it. We know this will not be great when I deploy my app to other computers. I would like to know the best way to save these credentials and allow someone to set them after installling the app (like how it is done with other apps). May be saving them to a text (.txt) file?

How do I save the details/variables to a text file?
How do I read/call these variables to my forms?
Posted

1 solution

Save them to a config file:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "ConnectionString", and set the Value to blank. Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
Dim s as string = Properties.Settings.Default.ConnectionString
5) To write your setting:
Properties.Settings.Default.ConnectionString = "My new setting value"
Properties.Settings.Default.Save()
The connection details will be saved in an XML file that is nice and easy for external programs to edit if necessary.
 
Share this answer
 
v2
Comments
savedlema 13-Apr-13 8:54am    
Thanks OriginalGriff!

But, with VB 2010, I see that "Properties" is not accepted/supported. I see its My.Settings.ConnectingString...
But thank you, I could learn some syntax.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900