publish a project with local database

后端 未结 1 1197
盖世英雄少女心
盖世英雄少女心 2020-11-30 06:47

I created a Windows form applicatie with a local database (.mdf) to store and retrieve data from. the database where I connect to is: C:\\ProgramData\\project\\Database.mdf<

相关标签:
1条回答
  • 2020-11-30 07:26

    Did you include the database as "Application File"? If not do the following (at least this is how I am doing it):

    Project -> Properties -> Publish -> Application Files

    Here set the values for your .mdf and the xx_log.ldf as follows:

    enter image description here

    Now still in the Publish tab go on Prerequisites. Here you have to check the following depending on what database you are using.

    enter image description here

    This will download SQL Server Express for the client who is installing your application.

    You will also have to change the connection string to a generic path. I suppose the database lies somewhere inside your project folder /bin I guess, not sure anymore. So adjust your connection string to something like:

    Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True
    

    I therfor recommend using a resource file or app.config

    But basically i think your problem is that the pc you are installing on does not have SQL Server installed. So just follow the steps above in Prerequisites. The other steps will enable you to deploy the database to the project folder without moving it to a certain folder manually.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题