Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made GUI that can perform usual operations with the database ( load existing data, modify it or add new entries). GUI is made in C++ using raw WinAPI.

The problem is in connection string. It is hardcoded so it forces the user to keep the database in the same folder where the GUI is.
Below is the example in C++, using ADO:
C++
static wchar_t *bstrConnect= L"Provider=Microsoft.ACE.OLEDB.12.0;\
                                 Data Source = .\\MyDatabase.accdb";

I wish to allow user to have freedom of choice when it comes to where database will be located but I do not know how to modify the application/connection string to do this.

I have tried to search here for examples, and have searched online but had no success. Perhaps me being a beginner and self-taught has something to do with that.

QUESTION:

Is there an example/tutorial/documentation that can show me the correct principle for handling this type of "scenario"?
Posted
Comments
ZurdoDev 23-Jan-15 12:30pm    
Just store it in a text file then. You can even encrypt the value if needed.
KarstenK 23-Jan-15 12:38pm    
Or in the registry. Think also about security. The password should be encrypted, or best NEVER stored but every program launch be asked. (with user name)

1 solution

Not sure if I understood your question correctly, but why not store the database location in a simple configuration (text) file in the same folder where the application is.

The first time the application runs, let the user specify the database location with a File Open dialog and store the location in the configuration file. Personally I wouldn't store the whole connection string in this case, just the location and then build the connection string in the program.

What comes to security I'd use a database password for the database and when the database is opened I'd ask the user for the password. I wouldn't store the database password anywhere.

About database password, see Set Database Password and Unset Database Password[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Jan-15 14:39pm    
5ed.
—SA
Wendelius 23-Jan-15 14:41pm    
Thanks :)

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