如何运行对一个MDF文件的SQL脚本? [英] How to run an SQL script against a MDF file?

查看:130
本文介绍了如何运行对一个MDF文件的SQL脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了使用Entity Framework的4.0模式,第一种方法数据库模型。然后,我使用的生成数据库从型号... 的我也已经在我的App_Data文件夹中创建一个SQL Server数据库文件中创建一个SQL脚本。我怎么现在跑反对这个MDF文件的SQL文件?

I've created a database model with model-first method using Entity Framework 4.0. I then created an sql script using the Generate Database from Model... I've also created an SQL Server Database file in my App_Data folder. How do I now run the SQL file against this MDF file?

我在使用Visual Studio 2010。

I'm using Visual Studio 2010.

推荐答案

我找到了解决办法,但它是一个有点哈克。

I found a solution, but it's a bit hacky.

我的SQL Server防爆preSS(2008 R2)。因此,从模型生成数据库,当我连接到它,让它建立数据库出现。然后我去 C:\ Program Files文件\ Microsoft SQL Server的\ MSSQL10_50.SQLEX $ P $干燥综合征\ MSSQL \ DATA 。在10_50部分是因为该版本可以为你不同。因此,此文件夹中有一个名为就像数据库.mdf文件 - .MDF。还有一个_log.ldf文件。我复制到这些到我的项目的App_Data文件夹。

I have SQL Server Express (2008 R2). So when generating the database from the model I connect to it and let it build a database there. Then I go to C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA. The 10_50 part is because of the version and can be different for you. So in this folder there's a .mdf file named just like the database - .mdf. There's also a _log.ldf file. I copied these to into the App_Data folder of my project.

这工作,但会消耗来生成一个新的.mdf数据库模型中的每一个变化很花时间。所以,我这样做只是在装运前。

This works but is very time consuming to generate a new .mdf database for every change in the model. So I do this just before shipping.

如果你找到一个更好的答案请你分享。

If you find a better answer please do share.

这篇关于如何运行对一个MDF文件的SQL脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆