Results 1 to 5 of 5

Thread: Deploying with Access Database Reference

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    2

    Deploying with Access Database Reference

    Hi, I'm new to VB.Net so bear with me.

    I've built a simple test application using the 'Server Explorer' to add a Database Connector to access the MS Access database I am using, I have then added dbAdapters (OleDbDataAdapter) to my form to access several seperate tables.

    The problem I face it that when I build the application for deployment it maintains the hard coded reference to the database. Therefore, when installed on a new machine the application will complain that it cannot find the database.

    How do I change the OleDbConnection objects properties to access the database in the current app path, or amend the deployment project to include the database as part of the application with no 'hard coded' file address?

    Thanx.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Well, your application will always require a concrete connection string.

    What you can do is include an application configuration file in your solution. In that, you need to add a value that is your connection string. Since this app.config file (gets changed to yourexename.exe.config when the application is distributed) is just an xml file, you can go in after the application is compiled and adjust it how you need to. This prevents you from having to recompile and redistribute your application when the location of the database changes or the password changes.

    It will look something like this when you are done:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appsettings>
    <add key="ConnectionString" value="YOURCONNECTIONSTRINGHERE" />
    </appsettings>
    </configuration>


    In your code, you will use the System.Configuration namespace to get at that setting. The statement will be something like this:

    Dim conn as new OleDbConnection(ConfigurationSettings.AppSettings("ConnectionString"))

    Since you used the server explorer to create a connection to your db, you will have to look through the code that windows generates to find where it sets the connection string. Edit that to the above statement, or a variation of, and you should be good to go.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    2
    Thanks for the advise, that's a nice way to set the database connection string, however I am unable to find where 'Server Explorer' creates the connection string.

    Will I need to go back and re-code the application using a data connector which I create, or is there a way to find whre the Server Explorer generates the code?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It'll be in the region labelled " Windows Form Designer generated code "

  5. #5
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830
    Can't you just put the database file in the "BIN" directory? I know this works when you move the project to a different PC but I don't know if it works when trying to deploy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width