0

I'm trying to place a .mdf database on a Computer A and access it simultaneously on Computer B but I'm having an error that says I cannot access the mdf file because it's being used by another process.

The setup is, the database is hosted on a Public folder in Computer A. I have Visual Studio running on both computers, and Computer B accesses the database on Computer A.

Computer A Connection path string:

C:\Users\Public\database.mdf

Computer B Connection path string:

\192.168.254.8\Public\database.mdf

Is there some sort of setting that I do not know of to enable multiple access on a db? Or this is not possible?

EDIT:

Let me rephrase my question, sorry.

There are two computers connected via a network, and I want to access one Visual Studio solution/project website. I wanted to do this as a demonstration, is it possible?

2
  • Which DBMS you're using? Commented Jan 23, 2012 at 13:19
  • @Oleg SQL Server Express, sorry. Commented Jan 23, 2012 at 14:16

5 Answers 5

1

You should have an instance of SQL Server (even express) running on the host machine.

All requests from the clients should use the standard mechanisms for connecting to that server instance. In other words, they won't run their own copy of SQL Server, instead they will connect to the instance running on the host machine.

Sign up to request clarification or add additional context in comments.

2 Comments

I just realized this. The difference is I'm opening instanced of Visual Studio itself and thus SQL Server on two computers. So I cannot do this? Because I was trying to do a demo with two computers accessing the same project.
Visual Studio can connect using a remote instance of SQL Server. I do it all the time. Just set it up in your connection string.
1

Simultaneous or direct access to Database files under any DBMS control either a very bad practice or simply impossible.

Use proper DBMS tools to access the data.

And yes - its possible to access Web site project for demo.

2 Comments

But how do I deploy the project on a server? There will be several employees using the system and it only has one .mdf located in the server. Each employee has a computer which has to access the .mdf, so it's the same case, right?
@Chris made me realize that the difference is I'm running Visual Studio on 2 computers thus I'm running two instances of SQL Express as well. But Can I do this for demonstration purposes? Two computers connected via network and accessing the Website project?
0

Install SQL Server on the host machine (the one that you want to keep your database on).

Then in Visual Studio, use the "Server Explorer" to locate the remote instance of the database. From there, you can utilize the remote instance of SQL Server in your connection string, thus allowing you to connect multiple computers to a single database.

Using two instances of SQL Server to connect to the single .mdf file is a very bad practice.

2 Comments

This is what I'm doing now. The connection string is \\192.168.254.8\Public\database.mdf but I get an error: *.mdf is already used by another process or located in UNC Share.
Exactly... "located in UNC Share". you don't connect to the MDF. You connect to the SQL Server Instance. Data Source=192.168.254.8;Initial Catalog=database;User Id=myUsername;Password=myPassword;
0

Instead of specifying the MDF file in your connection string (which, I believe, uses a form of User Instancing), you should use SQL Server Management Studio (SSMS) to attach the MDF. Then connect to SQL Server, rather than to the MDF.

You may need to move the MDF and LDF files to a place where the SQL Server identity can access them, rather than keeping them in your VS project.

Most projects keep scripts to create the DB in their VS project, but not the binary MDF itself.

When you deploy, the process is similar: use SSMS to attach the MDF on your server.

2 Comments

What should the ConnectionString look like?
Usually, something like this: Data Source=YourServerNameOrIP;Application Name=YourAppName;Initial Catalog=YourDBName;Integrated Security=True
0

Yes, If 2 or More Computers are connected by networks like LAN You can access the Database Database1.mdf (say) from another SQL Server by entering its user name / Password /by Visual studio connection.

Disadvantages:

If more than 7~8 systems are accessing same Database same time System response slows down and Hangs up or may result error like connection pool exceeded or Device not responding..

In Big Companies they use Huge Multi-core & Multi-Processer based sever which will respond faster.

Overcome: while writing Applications Use Connection Open and Close Particularly while executing the SQL queries in other time it should be closed.

Best Programer uses Transaction instead of using normal methods. Transaction Makes Every User Access Database With valid and successful Execution of queries. These Queries (Transaction Queries) mainly executes on client machine and later updates the same over Main server when it got Time slot for it(synchronize).

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.