ODBC interface for changing login way

4 views (last 30 days)
Cristian Martin
Cristian Martin on 13 Jun 2022
Edited: Shantanu Dixit on 22 Jan 2025
Hi, is there a way before I pack a GUI to an exe file to make an interface for later changing the connection ODBC to SQL server after that in case that server IP is changed meanwhile? Or I must to recode the source code and pack again? Thanks! R2015a

Answers (1)

Shantanu Dixit
Shantanu Dixit on 22 Jan 2025
Edited: Shantanu Dixit on 22 Jan 2025
Hi Cristian,
You can allow dynamic changes to ODBC settings for server IP address without needing to recompile your application by implementing a configuration file. Below is a generic approach you can take:
1. Creating a configuration and reading
You can use a simple text file (e.g., '.json' or '.yaml') to store the connection settings. The file can include parameters like server IP, database name etc. Before establishing the connection, you can read the configuration file to retrieve the current settings.
configData = jsondecode(fileread('config.json'));
server = configData.server;
databasename = configData.database;
2. Set up the connection
You can now use the retrived configuration to set up your connection using 'database'
conn = database(databasename,username,password,'Vendor','MySQL','Server',server) %% can add more args as required
Following the above approach you can create a simple GUI that allow users to modify the configuration file. MATLAB provides 'uicontrol' to create text fields and buttons which can be used to change/modify the connection settings. You can write back these settings to the configuration file when changes are saved. The application can be packed as an executable once it is setup to read from and write to a configuration file, making the updation file without needing to recompile the application.
You can refer to the following useful detailed documentation from MathWorks:
Hope this helps!

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!