Search code examples
c#winformsmdf

how to run app with mdf database in another pc


I have a windows form app project with mdf database the app work fine in my pc but when i try it on another pc it dont work and no connection to database (the database with app in same folder)

This is connection string

SqlConnection sqlCon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Contact.mdf;Integrated Security=True;Connect Timeout=30");

How to use my app with this mdf database in another pc?

It run in my pc when I installed localDB 2016 but I can't install localDB 2016 in second pc because it is 32bit machine.


Solution

  • You cannot execute queries against MDF files, you cannot use them directly without attaching them with database service.

    Best solution in your case will be to install SQL Express or appropriate database service on the second computer. Then you can take back up from first machine and restore on second machine. OR you can also create brand new database on second machine using your database creation scripts and use it.

    Hope this helps.