12

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

when I publish my project and place my database file in that folder on a other pc and try to run it I get the error unable to locate a local database runtime installation

my connection string is:

conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\ProgramData\project\Database.mdf"";Integrated Security=True";

so could somebody help me with this problem? because everything runs fine on my own pc

4
  • What exception are you getting exactly?
    – Peter
    Feb 4, 2015 at 12:33
  • System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) ---> System.ComponentModel.Win32Exception (0x80004005)
    – Ewout
    Feb 4, 2015 at 12:41
  • Do you actually use the same path (C:\ProgramData\project\Database.mdf)?
    – sloth
    Feb 4, 2015 at 12:45
  • that is the location of my database file so I can always acces it on a other pc when I place it there
    – Ewout
    Feb 4, 2015 at 12:51

1 Answer 1

16

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.

1
  • thanks including sql server in the prerequisites worked
    – Ewout
    Feb 4, 2015 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.