ASP.NET 成员资格设置 - 数据库问题
我正在设置会员提供商,因此收到以下错误消息:
尝试为文件附加自动命名数据库
C:\Users\Mcoroklo\Desktop\Programmering\Private Projekter\ASP.NET\Helpdesk\Version4\HelpDesk\ClientSite\App_Data\ASPNETDB.mdf 失败的。同名数据库 存在,或者指定的文件不存在 打开,或者位于 UNC 共享上。
我是建立会员资格的新手,所以我不能否认缺少一些真正重要的东西! :-)
我非常确定这与我的连接字符串和/或 SQL 成员资格提供程序有关。我的 web.config 中有以下设置:
我的连接字符串:
<connectionStrings>
<add name="MembershipServer" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf; Trusted_Connection=Yes;"/>
My SQL 提供程序
<membership defaultProvider="AspNetSqlProvider">
<providers>
<clear/>
<add connectionStringName="MembershipServer"
name="AspNetSqlProvider"
applicationName="/"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
我的身份验证和授权:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="Site/Login.aspx"
cookieless="UseCookies" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
我网站中的文件结构是我的目录中有两个本地数据库。成员资格(ASPNETDB.MDF)是我用连接字符串指向的成员资格。我使用 ASP.NET 工具来创建它。
我通过 LINQ TO SQL 类连接到的另一个数据库位于不同的项目中(使用层)。
非常感谢!!
I am setting up a membership provider, and as a result, I am getting the following error message:
An attempt to attach an auto-named database for file
C:\Users\Mcoroklo\Desktop\Programmering\Private
Projekter\ASP.NET\Helpdesk\Version4\HelpDesk\ClientSite\App_Data\ASPNETDB.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
I am new to setting up membership so I can't deny something really crucial is missing! :-)
I am quite sure this has something to do with my connection string and/or SQL Membership provider. I've the following setup in my web.config:
My connection string:
<connectionStrings>
<add name="MembershipServer" connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf; Trusted_Connection=Yes;"/>
My SQL provider
<membership defaultProvider="AspNetSqlProvider">
<providers>
<clear/>
<add connectionStringName="MembershipServer"
name="AspNetSqlProvider"
applicationName="/"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
My authentication and authorization:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH" loginUrl="Site/Login.aspx"
cookieless="UseCookies" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
The file structure in my website is I've two local databases in my directory. The membership one (ASPNETDB.MDF) is the one i point at with my connection string. I've used the ASP.NET tool to create it.
The other database I connect to via LINQ TO SQL classes and is in a different project (using tier layers).
Thanks a bunch!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Visual Studio 将为您初始化所有这些。你妨碍了它。它尚未为您创建和配置该数据库。
删除连接字符串元素、成员资格元素、身份验证元素和授权元素。
或更好从新的 Asp.Net 应用程序开始
然后单击项目(或网站)> Asp.net 配置并按照步骤操作。
否则,您将需要使用 aspnet_reqsql.exe 创建并配置您自己的数据库。
Visual Studio will initialize all of that for you. You are getting in it's way. It has yet to create and provision that database for you.
Delete the connection strings element, the membership element, the authentication element and the authorization element.
or better yet Start with a fresh Asp.Net Application
Then click Project(or website)> Asp.net Configuration and follow the steps.
otherwise you will need to create and provision your own db with aspnet_reqsql.exe.
尝试删除数据库名称之前的 \。
AttachDbFilename=|DataDirectory|ASPNETDB.mdf
而不是:
AttachDbFilename=|DataDirectory|\ASPNETDB.mdf
哦,另一个想法是,您的计算机上确实加载了 SQL Express,对吗?
Try removing the \ before the database name.
AttachDbFilename=|DataDirectory|ASPNETDB.mdf
instead of:
AttachDbFilename=|DataDirectory|\ASPNETDB.mdf
Oh and another thought, you do have SQL Express loaded on the machine, correct?
请记住,machine.config 定义了一个名为“LocalSqlServer”的连接字符串,默认情况下您的应用程序将使用它。
要解决这个问题,要么像这样显式删除名称:
要么使用clear,但我还没有测试它:
通常我所做的只是覆盖LocalSqlServer,所以我的连接字符串被命名为相同的,这似乎可以解决大多数问题。
就像其他人提到的那样,当您使用 ASP.NET 站点管理器设置应用程序时,您正在附加 ASPNETDB,而它应该为您执行此操作。
Remember that machine.config defines a Connection String with the name "LocalSqlServer" and by default your app will use that.
To fix the problem, either explicitly remove the name like this:
or use clear, but I haven't tested it:
Usually what I do is just overwrite the LocalSqlServer, so my connection string is named the same, that seems to fix most problems.
Like others have mentioned, you are attaching the ASPNETDB when it should do that for you when you setup your app using the ASP.NET Site Manager.