[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Replacing .ini files used for Access applications which I migrate to .Net C#

Posted on 2014-08-27
10
Medium Priority
?
305 Views
Last Modified: 2014-09-01
Hi

I have a number of Access VBA apps to migrate to C#. My Access apps have to be able without software changes to access data either in a prod environment or in a test environment, both being on separate SQL Server DBs on separate Windows servers. To achieve that I use an .ini (text) file which they look for when they are starting and which tell them which DB to access (the ini file contains entries for DB type, name, server and DSN name). Currently I have one central ini file for each environment, and I use 2 sets of shared network directories, one for prod, one for test, with the ini files in the corresponding root directories of each environment. So the apps look for the ini file first in their own directory, and if finding none, go up the directory tree until they find the central ini file, read it, and relink all their tables to the appropriate DB.

What would be the recommended way to achieve a similar result with C# apps ? I've heard about config files but know nothing about them, really. WHat I want to avoid is to have to duplicate the apps.

Thanks for your input
Bernard
0
Comment
Question by:bthouin
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 40288576
The config file is the new ini file.

For windows applications, just add a configuration file called App.Config

When it's compiled, the app.config turns into

MyExe.exe.config

which can then be read by the Application.

More on how to read from the application config can be found here:
http://geekswithblogs.net/akraus1/archive/2006/01/04/64871.aspx
0
 
LVL 40
ID: 40289060
Kyle is right, but the easiest way to learn how to use the configuration file is the official documentation on the MSDN site.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40289378
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:bthouin
ID: 40289823
HI guys

Thanks for your posts, now I now everything I need to know about config files.

However, they don't really solve my problem:
- ideally, I don't want a config per app, I want one for a group of apps which all reside in subdirectories of a given root directory. I have one root dir for prod and one for test, and all apps are in various subdirectories ot the corresponding root dir. In other words I have the same app always twice, once in a subdir of the prod root dir, one in a subdir of the test root dir. All the apps under one root dir should connect to the same prod SQL Server DB on the same remote server. Therefore I need only one config for prod apps and one config for test apps
- I don't like at all the idea that a config file (which can be open with Notepad or IE) is going to lay open to look into for any curious user (and, who knows, potential hackers), outlining nicely on which server the DB is and which name the DB has. God knows what users are capable of, not to talk about hackers...
- the last thing I want is that my users could decide which DB to use (as suggested in Eric's article). That must in any case remain hidden to them

Is there no way to have such a config file at another location than where the executable is, i.e. can one "tweak" the code reading the config to use another source diretory for the config file and another, generic, file name ? Or do I have to do that all myself by creating an xml config file myself and writing the code to read it at a given "logical" location on the file system (as I do currently in Access) ?
0
 
LVL 1

Author Comment

by:bthouin
ID: 40289881
Well, it seems I found somebody who has had exactly the same idea as me. Googling the problem, I found a C# project on the Code Project site, called Configurator, which covers EXACTLY what I need, and not only that, but it can even convert my existing ini filse into XML config files...

So I'd say, problem pretty much solved !
0
 
LVL 40
ID: 40290351
Since all your applications are working with the same DB, why not have a table in that DB to store your configuration.
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 40290491
He would still want some kind of configuration to point between them.  Can you point a link to the project?

Also XML is still clear text so it won't keep it from "prying eyes".  The best way to do that would be to write some kind of utility that uses a symmetric encryption key, and then you can write values out to the config and read them in.

Just my 2 cents.
0
 
LVL 1

Author Comment

by:bthouin
ID: 40290985
@James: this would be a catch22 situation. By definition I cannot have the app to access the DB to find out which DB to connect to...

My 10+ user applications have each to know if they should connect to the Prod or the Test DB. This depends actually on where an app is stored. If it is stored in a subdirectory belonging to the Prod directory tree, then it should connect to the prod DB. That's why I was looking for a mechanism for the apps to look into a file on the file system that will tell them to which DB to connect.

@Kyle: yes, you're right, but that's a bit overkill, as now the config file will not be where the apps are but in a different (parent) directory at least 2 levels up from the apps themselves. That should be sufficient hiding. If not, I have done symmetrical encryption before in my career, so I could absolutely do what you suggest. Thanks.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 600 total points
ID: 40291028
If all you need is the database to connect to, a simple text or binary file on the network can do the trick. It does not have to be a .config file. Encrypt it if you need to.

Depending on how you decide to distribute your updates, the databases location can also be hidden in the application itself. A ClickOnce distribution for instance makes it a snap to recompile and redistribute the application with a new value for the constants it contain.
0
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 900 total points
ID: 40291168
I would not trust that the config file being in a different directory (especially if it's in a sibling) being "secure enough".  Anything that can go wrong will go wrong.  A user still might be able to find it, and as a developer that case should be handled.  


If you're launching from a network path . . . you could store all additional settings in the database.  If the DB or paths ever changed, simply update it here, recompile and you're good to go.  

Set the connection string (hardcoded on load).

Something like:


string connStr;

if (inProdPath())
   connStr = "..."; // prod conn str hardcoded
else
   connStr = "---"; // test conn str  hardcoded

LoadSettingsFromDatabase(connStr);

Open in new window


Again, just my 2 cents, and trying to help you achieve your goal.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question