Visual Studio 2010 中的数据库在哪里?
我正在使用 Visual Studio 2010 Professional 在 (C#) ASP.NET MVC3 中创建我的第一个项目,我正在创建一个非常基本的博客系统。在测试期间,我创建了一些表,现在我想在这些表上存储不同的数据,但我不断收到此错误:
自创建数据库以来,支持“CategoryContext”上下文的模型已更改。手动删除/更新数据库,或使用 IDatabaseInitializer 实例调用 Database.SetInitializer。例如,DropCreateDatabaseIfModelChanges 策略将自动删除并重新创建数据库,并可选择使用新数据为其播种。
显然,我需要更新数据库中的表,但我找不到可以访问这些表的位置。我可以使用 CTRL+ALT+S 打开服务器资源管理器,但那里没有数据库或表。
这是它的屏幕截图:
http://img710.imageshack.us/img710/8944/screenshot001kd.png
我在哪里/如何找到和/或编辑实际的数据库表?
谢谢。
I'm creating my first project in (C#) ASP.NET MVC3 using Visual Studio 2010 Professional, I'm creating a very basic blog system. During the tests I created a some tables and now I want do store different data on those tables but I keep getting this error:
The model backing the 'CategoryContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
Obviously I need to update the tables in database but I can't find where I can access the tables. I can open Server Explorer using CTRL+ALT+S but there is no Database or tables there.
Here is the screenshot of it:
http://img710.imageshack.us/img710/8944/screenshot001kd.png
Where/how can I find and/or edit the actual database tables?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我能为您做的最好的事情:
如果使用 SQL Compact Edition,那么您应该查看文件系统上的项目文件夹并查找名为 app_data 的文件夹,其中应该有一个数据库。
或者,您可以打开 web.config 文件并查找“ConnectionStrings”部分,然后查找数据库的位置。
如果它在 SQL Server Express 中,则在数据库资源管理器窗口中,单击数据库连接并创建到本地 sql server express 的连接。您应该在数据库列表中看到它作为 machinename\sqlexpress。
Well here is the best I can do for you:
If using SQL Compact Edition then you should look into your project folder on the filesystem and look for a folder called app_data and you should have a database in there.
Alternativly you could just open your web.config file and look for the section that is the "ConnectionStrings" section and just look for the location of the database.
If it is in SQL Server Express, then in your Database Explorer window, click on the database connections and create a connection to your local sql server express. You should see it in the list of databases as the machinename\sqlexpress.
根据您的错误,我猜测您正在使用实体框架的代码优先方法。
发生的情况是实体框架已在本地 sql Express 安装上为您创建了一个数据库。要查找实际的数据库,请查看 web.config 文件并找到连接字符串部分,该部分将告诉您数据库的服务器和目录。您可以使用 Visual Studio 通过使用图片中服务器资源管理器面板中的数据连接区域来访问数据库。或者您可以使用 Sql Server Management Studio 来执行相同的操作。
现在,您收到错误的原因是因为实体框架根据您最初定义的实体创建了该数据库。进行更改后,数据库将不再与实体匹配,并且您会收到上面列出的错误。您的解决方案是在找到数据库后将其删除并允许自动魔法再次发生,或者您需要对代码进行一些更改,以便在每次进行方案更改时不自动生成数据库。
我建议您查看 MSDN 的 ADO.NET Entity Framework 4.1 并阅读“代码优先”的开发风格。
祝你好运,希望这对你有帮助。
From your error I'm going to guess that you're using Entity Framework's code first approach.
What happened is that Entity Framework has created a database for you on the local sql express install. To find the actual database, look in your web.config file and find the connection string section which will tell you the server and the catalog for the database. You can either us Visual Studio to access the database by using the data connection area found in the server explorer panel in your picture. Or you can use Sql Server Management Studio to do the same thing.
Now the reason why you're getting an error is because Entity Framework created that database based on the entities which you initially defined. Once you have made changes, the database no longer matches the entities and you get the error listed above. Your solution is to either delete your database once you have found it and allow the auto-magic to happen again, or you will need to do some changes to your code to not auto-generate your database each time you make scheme changes.
I would suggest you look through MSDN's ADO.NET Entity Framework 4.1 and read up on 'code first' development styles.
Good luck, and hope this helps you some.