CTP4 Code First - SQL Express用户实例连接的挑战 [英] CTP4 Code First -- challenges with SQL Express user instance connection
问题描述
您好,
我正在尝试使用单个用户实例SQL Express数据库,其中包含ASP.NET默认应用程序服务提供程序表和从我的代码生成的表第一个DbContext。
I am trying to use a single user instance SQL Express database that contains both the ASP.NET default application services provider tables and the tables generated from my code first DbContext.
我添加了一个连接字符串,其名称与我的DbContext匹配,连接字符串和providerName与ASP.NET MVC 2 Web应用程序项目模板添加的默认ApplicationServices连接相匹配。新的连接字符串如下所示:
I added a connection string with a name matching my DbContext and a connectionString and providerName matching the default ApplicationServices connection added by the ASP.NET MVC 2 Web Application project template. The new connection string looks like this:
<add name="Trs.Model.TrsContext"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
运行网站时出现错误:
  ;
未创建数据库。我按如下方式修改连接字符串以指定初始目录:
The database is not created. I modify the connection string as follows to specify an initial catalog:
<add name="Trs.Model.TrsContext"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=TRS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
现在,当我运行应用程序时,数据库已成功创建。代码第一个表是创建的,但是没有"aspnet_";表。尝试登录该网站会导致此错误:
The database is now successfully created when I run the application. The code first tables are created, but there are no "aspnet_" tables. Attempting to login to the website results in this error:
然后我尝试将相同的初始目录值添加到ApplicationServices连接字符串。当我删除数据库并重新运行时,网站启动时出现错误:
I then try adding the same Initial Catalog value to the ApplicationServices connection string. When I delete the database and re-run, I get an error when the website starts up:
我意识到有其他选择 - 不要使用一个用户实例,使用两个独立的数据库,尝试SQL CE - 但共享用户实例目前最适合我的项目。
I realize that there are alternatives -- don't use a user instance, use two separate databases, try SQL CE -- but the shared user instance is the most ideal fit for my project at this time.
该项目是vanilla。唯一的修改是向global.asax Application_Start事件处理程序添加一些代码以调用Database.SetInitializer,创建上下文的实例,并添加一些示例数据。
The project is vanilla. The only modification is to add some code to the global.asax Application_Start event handler to call Database.SetInitializer, create an instance of the context, and add some sample data.
有什么想法吗?
Gary
推荐答案
嗨Gary,
感谢您引起我们的注意,这似乎是Code First和ASP.Net认为他们拥有数据库的问题。我们将看看这个场景并尝试
并在RTM之前对其进行改进,但与此同时我建议使用您提到的替代方案之一。
~Rowan
这篇关于CTP4 Code First - SQL Express用户实例连接的挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!