Search code examples
vb.netvisual-studio-2012crystal-reports

How to publish my windows form application with database


I am developing Winform application using vb.net and MS Access in Viusal Studio 2012. I completed my application and now i just wanted to publish it. In my project Solution I have forms and rpt files (crystal reports). I use the following connection string to my database which is not included to my project solution :

     conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\tblcmplist.mdb"

Now the database should be there in folder where my application starts. If I run from the bin folder it works but if i publish my application by right clicking solution->publish and if i run from the published location i am getting error like the database file is missing.

I copied my database file to that startup folder of my application still the error occurs. What is the solution plz help me.

And one more thing I had to ask I am using crystal reports in my application. I installed CRforVS_13_0_5 developer version and I created reports in visual studio and I can view the report it works fine. But if I run the application in clients machin it gives the error could not find crystal report blah blah... what should i install in my client's pc to view the report ? Plz help me Thank you....


Solution

  • You will need to deploy your database as "IncludeData" in the application settings. That will make it appear in the folder defined by ApplicationDeployment.DataDirectory (running as a ClickOnce app). To test this from VS as well as deployed, you will want to do something like this:

    string dataPath;
    if (ApplicationDeployment.IsNetworkDeployed)
      dataPath = ApplicationDeployment.CurrentDeployment.DataDirectory;
    else
      dataPath = System.Windows.Forms.Application.StartupPath;
    dataPath = System.IO.Path.Combine(dataPath, "yourdatabasefilename");
    If you deploy it in the Database folder and mark it as Include instead of Include(Data), the datapath would be 
    Path.Combine(System.Windows.Forms.Application.StartupPath, "Database\yourdatabasefilename");
    

    If you deploy it as data, when you issue an update it will be copied forward. If you change the local copy of it, a new version will be deployed and the old version will be placed in a subfolder of the Data folder called .\pre. Then if you need to migrate data, you can. If you want more granularity over the replacement of your database, check out this article, which shows you how to retain data between ClickOnce updates: http://robindotnet.wordpress.com/2009/08/19/where-do-i-put-my-data-to-keep-it-safe-from-clickonce-updates/

    Source