How to connect two Applications in the same instance of Localdb

Asked

Viewed 44 times

0

I have a problem when connecting with the same instance of localDb in another application in the same solution.

Detailing the project, I have an ASP . NET MVC5 application in the solution and also another console application in the same solution.

As I built the database with code first in the MVC application, fix database first in the console. It generated me the table classes all right, but when I try to do some action in the database the following error:

Sqlexception: Cannot attach file 'C: Users E555555 source Repos PGP.Websolution Web App_data aspnet-Web.mdf' as database 'Web' because this database name is already Attached with file 'C: Users E55555555 source PGP.Websolution Console bin Debug aspnet-Web.mdf'

From what I understand you say that you can not use the same in the database because it is already being used by another file . mdf.

But I don’t want to create another mdf file, I want to use the existing one.

And the Connection string of the two applications are the same. How can I use the same file . mdf in more than one application?

Anyone who can help, thank you.

//ConnectionString em ambas aplicações

<connectionStrings>
    <add name="Default" connectionString="data source=(LocalDb)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\aspnet-BradescoPGPWeb.mdf;initial catalog=BradescoPGP.Web;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>
  • tries to take initial configuration Catalog out of its connection string

  • Lucas Miranda, I managed to solve creating the base on the Sqlserver installed on the same machine, without being the . mdf, so I was able to access the bases.

1 answer

0


I was able to resolve this issue using a locally installed Sqlserver instance on the machine. So I was able to access without problem the same base in two different projects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.