I have the following setup:
When I want to create a new table / fields in my system, I create it in deployment and then run those scripts on production without data.
Now, I am in the opposite situation: I've generated scripts from my production server, and wants to run those towards my local MDF file.
How do I do that? All the answers i've seen so far doesn't help me.
I've tried the following:
I've tried to run the whole SQL script in the "Run query" in Visual Studio, but I get a "The Set SQL construct or statement is not supported." error.
I guess I have to open the MDF file somehow in Microsoft SQL Management Studio - but I can't really find a way to get it all to work.
EDIT:
After half a year, I've been using the method suggested as the answer again and again. It is by far the best solution. No more MDF files in the project!
I would strongly suggest anyone reading this to start having your databases in your local database.
In my opinion, the whole AttachDbFileName= approach is flawed. Since that .mdf
file is not attached to your SQL Server instance that's already installed, there's many things you cannot do:
BACKUP
to back up your database.sql
scripts against your database The only really viable solution in my opinion would be to
YourDatabase
) 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...