How to dynamically connect to an access database


  • So my issue is this: I have created a small program that connects to an access database, only 1 table for now, and I have a hard coded connection string. the datasource=c:\users\me\files etc. I need to move my application to another desktop for testing(my friends), and I have no idea how to write the string so I don't have to go into the code to change it. I don't want to change the string at all, not even in the settings. Is there a way I can do this with Access, or do I need to use a sql database?

    If I need to use sql, what would that look like as well?

    thanks everyone!

    Thursday, December 06, 2012 5:57 AM


All replies

  • USe a config file or setting.ini file and write your connection string there.

    Put the config file parallel your application path.

    Code in your program to read that connection string in that file.


    Also you can use ODBC to conntect to the database. Then you only need to setup the ODBC, no need to change in the code.

    Please mark it as an answer/helpful if you find it as useful. Thanks, Satya Prakash Jugran

    Thursday, December 06, 2012 6:12 AM
  • include the app.config file in your project and write the connection strings into it. you can read the connection string from the file at runtime easily.

    Hirendra Sisodiya from

    Thursday, December 06, 2012 6:27 AM
  • The following link demonstrates  how to read and write into app.config:


    Hirendra Sisodiya from

    Thursday, December 06, 2012 6:33 AM