locked
Publish Winform connected to access database to a network drive RRS feed

  • Question

  • Hello all , 

    I have created a winform application which is currently in my C drive(desktop) connected to access database which is also present in bin/debug of my winform source folder.

    Now i want to 

    publish this in a network drive where two users can open this form and enter data .

    When i go to publish folder my database name is not showing in application file , hence i am not able to connect to it .

    please help how to publish this application.

    I have attached some photos which i think might help you providing me a solution.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="WindowsFormsApp1.Properties.Settings.TrialConnectionString"
                connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Trial.accdb"
                providerName="System.Data.OleDb" />
        </connectionStrings>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
        </startup>
    </configuration>


    Saturday, July 25, 2020 7:16 AM

Answers

  • Hi Ravi Kumar,
    You need to add any data files to the manifest before publishing and then follow the steps below:
    1.Select and right click Access DB file in Solution Explorer and choose properties.
    2. Change property "Build Action" to "Content" , and "Copy to Output Directry" = "Copy always".
    4. Then open Publish tab in Project Property and press "Application Files" button
    6. Make Sure that your DB File in list and its publish status = Include (Auto) and Download Group = (Required)
    Finally,  you can publish your application and Access DB file will be delopyed with application in "Data" folder of Installation folder of your application.
    Here is a document about including a data file in a ClickOnce application you can refer to.
     Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 27, 2020 3:05 AM

All replies

  • Hello all , 

    I have created a winform application which is currently in my C drive(desktop) connected to access database which is also present in bin/debug of my winform source folder.

    Now i want to 

    publish this in a network drive where two users can open this form and enter data .

    When i go to publish folder my database name is not showing in application file , hence i am not able to connect to it .

    please help how to publish this application.

    I have attached some photos which i think might help you providing me a solution.

    Target folder which i want publish

    Saturday, July 25, 2020 7:45 AM
  • Hello,

    Use the following free installer, read the documentation which will explain how to include other files such as your Access database.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, July 25, 2020 10:39 AM
  • You didn't specify how you "publish" your app and that is critical to solving the issue. If you're using an installer as Karen mentions then you need to look at their docs.

    If you're using ClickOnce then you need to add any data files to the manifest before publishing. That process is documented in MSDN.

    Alternatively, and in my opinion generally a better option, is to not ship the DB directly. This is just one more file to get lost. Either store the the data as an embedded resource in your EXE that you can extract on first run or rebuild the data instead. Embedded resources work well for small files like starter scripts. But your DB is 476KB so that is a little large. Consider creating a creation script that can regenerate the DB instead. Run the creation script on first run. This has 2 advantages. The first advantage is that it is likely smaller so you can more easily embed it as a resource.

    The second advantage is that you are no longer tying the data to the version that was available when you built the sample data. Suppose, for example, that you built that file using Access 2016. Access vNext comes out and MS decides that there are too many breaking changes so whenever you open older files you get a warning. When somebody installs your app they will get a warning opening the DB file because it is using an older version. However if you were to build the database from scripts then it'll use the current version that is installed. Of course this takes longer to run but unless you're talking about a massive dataset (which is probably not a good demo) then it is cleaner.


    Michael Taylor http://www.michaeltaylorp3.net

    Saturday, July 25, 2020 4:06 PM
  • Now i want to publish this in a network drive where two users can open this form and enter data .

    Be careful with this. If you intend to copy the application's executable to a network folder, and then have the users run it directly from he network, you are going to encounter a problem. When a .NET executable runs from the network, the Code Access Security (CAS) makes it run with reduced permissions. And one of the permissions that will be removed by default is the ability to access a database.

    It is possible to change the CAS permissions, but the way to do it depends on the Framework version, and it is probably more trouble than it's worth. You will find it much easier to copy the executable to the local drive of each PC and run it from there. The database itself is not a problem, you can place it in the network folder as long as the NTFS permissions and the sharing permissions allow it to be opened from the users' computers.

    Sunday, July 26, 2020 8:13 PM
  • Hi Ravi Kumar,
    You need to add any data files to the manifest before publishing and then follow the steps below:
    1.Select and right click Access DB file in Solution Explorer and choose properties.
    2. Change property "Build Action" to "Content" , and "Copy to Output Directry" = "Copy always".
    4. Then open Publish tab in Project Property and press "Application Files" button
    6. Make Sure that your DB File in list and its publish status = Include (Auto) and Download Group = (Required)
    Finally,  you can publish your application and Access DB file will be delopyed with application in "Data" folder of Installation folder of your application.
    Here is a document about including a data file in a ClickOnce application you can refer to.
     Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 27, 2020 3:05 AM
  • Thank you very very much
    Thursday, July 30, 2020 10:50 AM