0

i am developing an app where i am having a common sql server database .mdf put on a LAN Server which is needed to be connected to two or more different instances of a same application as other stations.

i am able to select the database but it is giving me and error posted below: enter image description here

how to overcome this? the connection string is

connectionString = @"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename = " + path + "; Integrated Security = True; Connect Timeout = 30";

P.S. it is working when a single instance is connected to it and it is preventing the second or third app to use it.

any help will be appreciated.

Yasar Khalid
  • 71
  • 2
  • 10
  • 2
    Possible duplicate of [multiple connections to an mdf file](https://stackoverflow.com/questions/19843631/multiple-connections-to-an-mdf-file) – jAC Jun 12 '17 at 07:35
  • You are working with `.mdf` file not with `database` – Darshan Faldu Jun 12 '17 at 07:50
  • 1
    *Applications* connect to the database, not the other way round. SQL Server isn't Access. `LocalDB` is a *local embedded* database, powered by SQL Server Express. Just use Express itself if you want multiple clients to connect – Panagiotis Kanavos Jun 12 '17 at 09:16

1 Answers1

2

You need to host the database on a network server. Several clients can connect to a SQL Server. But several clients cannot simultaneously connect directly to an MDF file.

The file alone cannot handle the concurrency. You need to have an application for it. That's where SQL Server comes into play.

After hosting, you need to change your connection string as well. Then it should work.

connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True"
samithagun
  • 664
  • 11
  • 25