locked
VB Publishing RRS feed

  • Question

  • So I always get this problem when publishing an application. All I did was connect to a database when I was testing it but when I publish it I get some error when trying to open the program saying that the database doesn't exist. What ever will I do?
    Wednesday, March 12, 2008 3:37 AM

Answers

  • Hi Jack,

    In this scenario you need to write the correct connect string to point out to the database file like Renee and Bort's suggestion.

    In this scenario you can read How to: Specify Which Files Are Published via ClickOnce to get the more information. Database file is the data file when we use clickonce to publish it. Commonly windows will put your database file to a data folder inside your user folder. We need to use Application.UserAppDataPath to point to this folder in order to access the file. Now after we updated the application, this doesn't overwrite the data file. I add a text file into project and set it as a data file and then publish it. I use
    Application.UserAppDataPath to point this text file. When you run the application in the target computer, you need to use Application.UserAppDataPath to find your database file. Try it.


    Best regards,
    Riquel
    Monday, March 17, 2008 2:15 PM
    Moderator

All replies

  •  

    You have to use a location that is symbolically available through the Application class, like Application.Startuppath and Application.applicationdata or Application.userapplicationdata in the construction of your connection string.

     

    I'm not sure those are the correct names but intellisense will let you know in an instant.

    Wednesday, March 12, 2008 4:01 AM
  • Say I used the Database Connection Wizard, how do I change the path?
    Wednesday, March 12, 2008 3:12 PM
  • Hey Jack,

    After going through the database connection wizard, your database file will be listed in the Solution Explorer window. Click on it, then, in the Properties window, set the Build Action to 'Content'.

    Other than that, find where you have referred to the database filepath in your code and change it from ("C:\...database.mdb") to (Application.StartupPath & "\database.mdb"). Don't forget to put the '\' in though, I did and it took me quite a while to work out what went wrong!!!

    Hope this helps.
    Bort
    Wednesday, March 12, 2008 4:57 PM
  • But what if Visual Basic made my connection string and everything, where do it edit it to change C:\ whatever to Application.StartupPath

    Wednesday, March 12, 2008 5:23 PM
  • So this idea I had looked very pleasant on paper however when I tried it I ran into one simple problem. See, publishing in my idea has been a down side in Visual Basic 2005 and 2008 and most things work until you want to publish it. I can get the program I made to access and input data into the database however when I want to mess with the database itself I can't. Heres what I want to do.

    First, my database connection I set to make the path simply "Bethel_Food_Pantry.mdb". Now to my understanding that views it to be in the folder in which all of my forms are. So theres that Bin folder, resource, what ever else and my forms. So then there is also the database right? Well thats what it says and it alls works. I understand the concept completely however heres what I want to do.

    When I'm debugging and when I'm using the published version all I want to do have a button that imports the database and exports it.

    The import will let me select a location in which my new database is located and it will delete the old one, and copy the one I had to where the old one is. My problem being is I don't know where the old one is when I'm debugging and when I'm using the finished version. Someone told me that I have to use something like Application.Filepath & "\database.mdb" but the thing is I'm using the new way to connect to a database with the wizard. I think you all get the picture here so any advice?
    Wednesday, March 12, 2008 11:02 PM
  • You need to change C:\.. to Application.StartupPath basically wherever it appears with regards to your database file. For example:

    Code Snippet

            Dim myConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\customers.mdb")
            Dim SQLQuery As String = "SELECT * from customers WHERE Company contains '" & frmQuoteGen.txtCustName.Text & "'"
            Dim FindCustomer As New OleDb.OleDbDataAdapter(SQLQuery, myConnection)

    Here.

    Hope this helps.
    Bort
    Thursday, March 13, 2008 9:39 AM
  • Hi Jack,

    In this scenario you need to write the correct connect string to point out to the database file like Renee and Bort's suggestion.

    In this scenario you can read How to: Specify Which Files Are Published via ClickOnce to get the more information. Database file is the data file when we use clickonce to publish it. Commonly windows will put your database file to a data folder inside your user folder. We need to use Application.UserAppDataPath to point to this folder in order to access the file. Now after we updated the application, this doesn't overwrite the data file. I add a text file into project and set it as a data file and then publish it. I use
    Application.UserAppDataPath to point this text file. When you run the application in the target computer, you need to use Application.UserAppDataPath to find your database file. Try it.


    Best regards,
    Riquel
    Monday, March 17, 2008 2:15 PM
    Moderator