Placing a LocalDB Database into AppData via Installer

831 views Asked by At

I developed an application (WinForm app built with VS2012) that uses SQL Server LocalDB.

I create the .exe file for the application and the database to install it on another machine using the Visual Studio 2012 tools (InstallShield Limited Edition or ClickOnce). The application installs on another machine, but when I launch it I receive this error message:

An attempt to attach an auto-named database for file C:\Users\%nom_utilisateur%\AppData\Local\Apps\2.0\Data\blabla\blabla\Data\Devessai.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on a UNC share.

Now when I copy the database to the path specified in the error message then application works perfectly.

How can I can put the database directly into the AppData folder via the application installer?

this is app.config:

<?xml version="1.0" encoding="utf-8" ?>  

<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="mdf_projet.Properties.Settings.DevEssaiConnectionString" 
              connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DevEssai.mdf;Integrated Security=True;Connect Timeout=30" 
              providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
1

There are 1 answers

0
Mohammed On

I solve the problem in click once in publish -> file Application -> selects the database and change publish status of the database to become data file.