ARTICLE AD BOX
I am using Visual Studio 2022 and trying to work with internal .mdf databases (LocalDB) for testing purposes in an ASP.NET Web Forms project using Entity Framework (EDMX).
Creating the database itself works without any issues. I can create a .mdf file inside the project's App_Data folder and connect to it successfully.
However, when I try to create an ADO.NET Entity Data Model (EDMX) from this database, Visual Studio throws the following error:
An error occurred while connecting to the database. The database might be unavailable.
An exception of type 'System.Data.Entity.Core.EntityException' occurred.
The error message is:
The underlying provider failed on Open.
The inner exception caught was of type System.Data.SqlClient.SqlException, with this error message:
An attempt to attach an auto-named database for file C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\UserBanco.mdf failed. A database with the same name exists, or the specified file cannot be opened, or it is located on a UNC share.
The important detail is that my actual database is located in the project folder:
C:\Users\<my-user>\Source\Repos\CrudUsuarios\CrudUsuarios\App_Data\UserBanco.mdfBut the error message shows that Visual Studio is trying to attach a database located in:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\UserBanco.mdfSo it seems like Visual Studio or LocalDB is trying to attach a different database with the same name, which causes the conflict.
Additional information:
Visual Studio 2022 .NET Framework 4.8.1 Entity Framework 6 LocalDB (localdb)\MSSQLLocalDB Database file stored in App_DataWhat could cause Visual Studio to try attaching a database from the Visual Studio installation directory instead of the one inside the project?
And what is the correct way to configure EDMX with a LocalDB .mdf database for internal testing in Visual Studio?
Any help would be appreciated.
