Anders
Anders

Reputation: 12736

Copy sql server database using Entity Framework?

I'm having a problem with copying or scripting my database at a web host (which I need for use in a test application), and I'm not getting much help from their support. They don't seem to know what's wrong, but I can't do it because of some "access rights" problem.

So for the time being I'm trying to think of a temporary workaround. All I need is the schema, not the data. So I was thinking, maybe I could import the entire EF model into the test application and use the generate database from model command? But of course, that model is connected to the current database, and I want to generate the schema in a newly created database I have, leaving the current database intact.

Is it possible to do this? Can I just change the connection of the model to the new database, or won't this work, are there other dependencies or something? If it does work, how exactly do I do this? And if it doesn't, is there some other way to achieve this without relying on the web host to find the problem with copying in the near future...?

Please keep in mind that I'm no expert at databases, I just know the basics of the Entity Framework and Linq to Sql, so any specific SQL ideas I probably wouldn't understand (stored procedures and all that...)

Upvotes: 0

Views: 1076

Answers (2)

Flavien Flandrin
Flavien Flandrin

Reputation: 3

You can export the schema of your database by: In server explorer => right click on the DB => Publish to provider and you follow the step. I will generate a SQL file that contains your schema and you import it on your server. Finally as Nik said you change the connection string.

Upvotes: 0

Nik
Nik

Reputation: 7283

You can copy your EF model and change the connection string. That should work fine.

Upvotes: 1

Related Questions