App database on C drive, installed on E drive

JohnM

Well-known member
Joined
Jul 2, 2004
Messages
116
Location
Massachusetts
Programming Experience
1-3
This is new to me. I do appreciate some help to understand. I created an application with.net. On a form I dragged over OLEDBDataAdapter onto the form to create a connection between a datagrid and an access DBase. I complete the steps. When I look at the properties of the OLEDBConnection for this I see alot of statements. One of them shows" SOURCE="C:\myfolder\mydatabase.."

Does this mean that when I create an installation (ex. an INNO installation) and the client runs the installation and lets say he downloads the application onto say his E drive, that my app won't work because of the "Source="C:\ etc connection I created in the app? or it doesn't matter because the databases are bury somewhere in the app and it doesn't matter what drive the client installs it on?

I apologize if this is very basic to you. I just don't know about it.

Thank you for your time

John M
 
If you have "C:\myfolder\mydatabase" had coded as a connection string, and the database is not there, then yes, your app is going to wind up in trouble.

If the database is to go in the same folder as you EXE (which would makes things infinately easier on you), then instead of using a hard coded path like "C:\whatever" us Application.ExecutablePath
 
When I dragged the Adapter unto the form and then follow the instructions of the wizard, I later saw in the code generated that the "C" drive was the source for all my databases. I would have to go into each of the forms where I used the wizard to create a connection, and change the path created with your suggestion right? In the future is there a way to have the wizard use the "path" you suggested automatically when it creates the connection?

John
 
I don't remember how this was in VS2003 but in later versions you add a Datasource and VS ask if you want to add the db to project, if you confirm the connectionstring is changed to include path |DataDirectory| which is a dynamic variable that solves all this.
 
I tried a couple of things. I went into the REGION generated code and when I tried to remove the hardcoded "C:" the connection property disappeared (when I clicked on the Connection icon and check its properties in the view window, it became blank. It looks like it won't allow any chnages in the code generated by .net under the Region section. The properties for Datasource doesn't have place to change its Source.

If using the Wizard to generate a connection to a database but it won't allow you to dynamically change its Source (from C: to whatever drive the user installs it to). Why use the Wizard? I did try to place the Application.StartUpPath to a string, but I got an error saying "connection changed from original form found in index XXX".

There has to be away to change the Source even after VB.net generates its code under the REGION section.:(
 
Wizard? What Wizard? (Just being factious) ;)
If using the Wizard to generate a connection to a database but it won't allow you to dynamically change its Source
It won't allow you to do lots of things that you should be able to do.

In the future, don't use the wizard. In the future, you take control of your application and have it do what you want it to, not what some wizard believes it should do.
 
Thank you for the heads up. I will try to create the database connection from code rather than the auto wizard. I wish I had posted a year ago and got your answer. In that time I created an app that has 41 different data bases. All their connection strings were created by the Wizard, dragging the OLEDBadapter from the tool bar over to the form.
I have alot of work to do. But I'll be a better programmer.

Thank you again for the direction.

John
 
I know this is a pretty "newbee" comment. BUT I just started to rewite the code for my 30+ database connections in the app :Dusing code rather than the wizard...and IT WORKS great! No more worrys about a client installing the ap on a different drive..

Thank you for the direction and advice.

John M
 
As time goes on you will discover lots and lots of reasons to write your own code rather than depend on wizards. This is just one of them. :)
 
Back
Top