在 EF 和 SqlRoleProvider 之间共享 SQLExpress 数据库
我在 SQLExpress 2008 中有一个数据库,可以通过 EF4 连接访问该数据库。它还包含网站的 ASP.Net 角色提供程序表。在 web.config 中有两个单独的连接字符串指向同一个数据库。当涉及到调试数据库时,我收到以下错误:
无法打开物理文件 “D:\ TFS \ Main \ Source \ TestWeb \ TestWeb \ App_Data \ TestDB.mdf”。 操作系统错误 32:“32(失败 检索此错误的文本。 原因:15105)"。尝试附加 文件的自动命名数据库 D:\TFS\Main\Source\TestWeb\TestWeb\App_Data\TestDB.mdf 失败的。同名数据库 存在,或者指定的文件不存在 打开,或者位于 UNC 共享上。
我认为这意味着两个不同的连接字符串不能同时附加到 SQLExpress 数据库?
以下是连接字符串:
<add name="SqlRoleManagerConnection"
connectionString="data source=.\SQLEXPRESS;
Integrated Security=true;AttachDBFilename=|DataDirectory|TestDB.mdf;
User Instance=false;MultipleActiveResultSets=True"/>
<add name="TestDBEntities"
connectionString="metadata=res://*/TestDB.csdl|res://*/TestDB.ssdl|res://*/TestDB.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\TestDB.mdf;
Integrated Security=True;User Instance=false;
MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
每个连接字符串上缺少左尖括号是故意的,这是由于 SO 的限制。
我有什么想法可以解决这个问题吗?
I have a database in SQLExpress 2008 that I am accessing via an EF4 connection. It also contains the ASP.Net role provider tables for the website. In the web.config there are two separate connection strings pointing to the same database. When it comes to debugging the database I get the following error:
Unable to open the physical file
"D:\TFS\Main\Source\TestWeb\TestWeb\App_Data\TestDB.mdf".
Operating system error 32: "32(failed
to retrieve text for this error.
Reason: 15105)". An attempt to attach
an auto-named database for file
D:\TFS\Main\Source\TestWeb\TestWeb\App_Data\TestDB.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
What I assume this means is that the two different connection strings cannot both attach to the SQLExpress database at the same time?
Here are the connection strings:
<add name="SqlRoleManagerConnection"
connectionString="data source=.\SQLEXPRESS;
Integrated Security=true;AttachDBFilename=|DataDirectory|TestDB.mdf;
User Instance=false;MultipleActiveResultSets=True"/>
<add name="TestDBEntities"
connectionString="metadata=res://*/TestDB.csdl|res://*/TestDB.ssdl|res://*/TestDB.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\TestDB.mdf;
Integrated Security=True;User Instance=false;
MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
Missing open angle bracket on each connection string is deliberate here and is because of a limitation of SO.
Any ideas how I can get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的情况:EF 和角色提供程序连接到同一数据库和两个连接字符串。但我的 ConnectionStrings 中没有“AttachDBFilename...”,而是在 RoleManager ConnectionString
Database=MyDb
和 EF ConnectionStringInitial Catalog=MyDb
中。在 SQL Server Management Studio 中,我已将物理数据库附加到对象资源管理器并命名为MyDb
。这有效。别问我为什么。关于连接字符串,我处于“让向导来做这些事情”的级别。他们以这种方式创建了字符串。I have the same situation: EF and Role provider connected to the same database and two connection strings as well. But I don't have "AttachDBFilename..." in my ConnectionStrings but instead in the RoleManager ConnectionString
Database=MyDb
and in the EF ConnectionStringInitial Catalog=MyDb
. In SQL Server Management Studio I have attached my physical Db to the object explorer and namedMyDb
. This works. Don't ask me why. Regarding connection strings I am on the level of "let the wizards do the stuff". They have created the strings this way.