Why do I get “Database already exists” when I'm using “AttachDbFileName” when I move the solution to another directory?

前端 未结 3 398
被撕碎了的回忆
被撕碎了的回忆 2021-01-24 02:32

I have an application JigSaw that uses a database TopScores.mdf which it is not included in the project. What I want to do is make the application find the database

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 02:40

    This is happening because you don't leverage the User Instance=true; when you connect to it. You literally told SQL Server to attach the database to the running SQL instance from the directory you first loaded it from.

    Detach the database by hand from the running SQL instance, change your connection string to use User Instance=true;, run it from the Debug folder, and then run it from the Desktop, and you'll see success.

提交回复
热议问题