|
-
Oct 30th, 2003, 06:56 PM
#1
Thread Starter
New Member
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.
-
Oct 30th, 2003, 11:53 PM
#2
PowerPoster
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.
-
Nov 2nd, 2003, 12:52 AM
#3
Thread Starter
New Member
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?
-
Nov 2nd, 2003, 01:25 AM
#4
It'll be in the region labelled " Windows Form Designer generated code "
-
Nov 2nd, 2003, 08:18 AM
#5
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|