locked
FAQ: How do I publish/deploy the WinForms application including a database file via ClickOnce? RRS feed

  • Question

  • How do I publish/deploy the WinForms application including a database file via ClickOnce?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Saturday, April 11, 2009 3:25 PM

Answers

  • Here is the walkthrough:

     

    1)     Create a new Windows Forms application.

     

    2)     Add Data Source (select a database file such as SqlDatabase.mdf) to your project.

     

    3)     Drag&drop DataGridView1 onto Form1, and using |DataDirectory| path in database connection string.

     

    Imports System.Data.SqlClient
    Public Class Form1
        'Binding database table to DataGridView
        Private Sub Form1_Load(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) Handles MyBase.Load
            Dim con As SqlConnection = New SqlConnection( _
               "Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")
            Dim cmd As SqlCommand = _
               New SqlCommand("SELECT * FROM Table1", con)
            con.Open()
            Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)
            Dim myDataSet As DataSet = New DataSet()
            myDA.Fill(myDataSet, "MyTable")
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
            con.Close()
            con = Nothing
        End Sub
    End Class
    
    

     

    4)     Select SqlDatabase.mdf file in Solution Explorer and look at its properties:

    Make sure the "Build Action" property is set as "Content".

    The "Copy to Output Directory" property is set as "Copy if newer".

    5)     Project Property -> Publish tab -> Press "Application Files" Button

    Check the database file in the list, and make sure its “Publish Status” is set as “Data File (Auto)” and “Download Group” is set as “(Required)”.

     

    6)     Project Property -> Publish tab -> Click the “Publish” button to publish your application.

     

    The database file will be deployed with the application in the "Data" folder of the application installation folder. An exe.config file will also be deployed along with the application in the application Installation folder.

     

    Related thread:

    http://social.msdn.microsoft.com/forums/en/vbgeneral/thread/92a2afc5-f168-454d-8e8b-6967aad45b72/

     

    For more FAQ about Visual Basic .NET General, please see Visual Basic .NET General FAQ

     



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Saturday, April 11, 2009 3:26 PM