Deploying an app w/ DB connectivity
-
I have been working on a project and have gotten it to a beta point. At this time, I wish to be able to give this application to other people to be able to test out the functionality. To do this, I have been working with creating a setup project. The problem that I run into is that the access database is not in the same location on the new machine as it is on my development platform. As a result, anytime a database call is made an exception is raised. I have looked for information on how to work with this (books, internet, friends), and have not been able to find any information. The only thing that I did find is that I cannot use xcopy to deploy the application. Does anyone know of an article on this site, or other reference that discusses how to create a setup project that will allow me to set the path for the db on the fly? Thank you in advance for all of the help, Eric VanWieren It is the nature of man to rise to greatness if greatness is expected of him. - John Steinbeck
-
I have been working on a project and have gotten it to a beta point. At this time, I wish to be able to give this application to other people to be able to test out the functionality. To do this, I have been working with creating a setup project. The problem that I run into is that the access database is not in the same location on the new machine as it is on my development platform. As a result, anytime a database call is made an exception is raised. I have looked for information on how to work with this (books, internet, friends), and have not been able to find any information. The only thing that I did find is that I cannot use xcopy to deploy the application. Does anyone know of an article on this site, or other reference that discusses how to create a setup project that will allow me to set the path for the db on the fly? Thank you in advance for all of the help, Eric VanWieren It is the nature of man to rise to greatness if greatness is expected of him. - John Steinbeck
Like you, I've written a couple programs that access a database. In order to do this with ADO.NET(which is what I use), you must set up a connection string inside your OleDBConnection object. The connection string gives(among other things) a path to your database file. When you add a OleDBDataAdapter object to your form, a wizard pops up to help you set up your connection. For example, when I set up a data adapter to my Access database, the designer adds this line of code to my program:
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source= **Path to your file here** ;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
I know that looks like a bunch of jibberish, but what you can do is before you open a connection to your database, modify your connection string to reflect where your database is. Because you don't know where the user will choose to install your program, you can use the System.Environment.CurrentDirectory property to locate where your application is running from and (assuming your database's location is based on the location of the app) append your database's path and name. My code to do this looks like this:string CurrentDir = System.Environment.CurrentDirectory; CurrentDir += "\\DB\\database.mdb";
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source="; this.oleDbConnection1.ConnectionString += CurrentDir; this.oleDbConnection1.ConnectionString += @";Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
I hope that helps. Dani