简体   繁体   中英

Visual Studio Cannot Find Database File

So I added a .mdf file to my solution just so I can have a basic database to read and write data to. However, every time I restart the program, the data I changed returns back to what it was prior to starting the program.

I read that this was due to it being copied to the source directory. However, when I do not copy it, Visual Studio is still looking in the same directory and it throws an error at run time. How do I fix this?

Fiddling around with SQL Server database files is always messy - at best!

The real solution in my opinion (seeing that you've already installed SQL Server Express) would be to

  1. install SQL Server Management Studio Express (if you haven't already done so)

  2. create your database in SSMS Express , give it a logical name

  3. connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:

     Data Source=.\\\\SQLEXPRESS;Database=YourDatabase;Integrated Security=True 

    and everything else is exactly the same as before...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM