ASP.NET ASPNETDB.MDF 无法打开数据库
我正在使用会员资格类别进行用户管理,它创建了一个名为 ASPNETDB.MDF 的数据库。我决定使用相同的数据库来处理我的其他数据,因此我在其中添加了一些我自己的表...
当我尝试访问它:
<connectionStrings>
<add name="connString" connectionString="Initial Catalog=MyProject;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MyName\Documents\Visual Studio 2008\Projects\Project\MyProject\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
使用这个:
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("connString").ToString)
通过会员类别登录后,它给我这个错误:
Cannot open database "MyProject" requested by the login. The login failed.
Login failed for user 'My-PC\Myuser'.
我不确定发生了什么?
编辑:如果我不使用会员资格类别,我可以很好地使用数据库..但是当我使用会员资格类别登录后,它会停止工作..
I am using membership class for my user management, and it created a database called ASPNETDB.MDF.. I decided to use the same database to handle my other data, and so I added some of my own tables in there...
When I try to access it:
<connectionStrings>
<add name="connString" connectionString="Initial Catalog=MyProject;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MyName\Documents\Visual Studio 2008\Projects\Project\MyProject\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Using this:
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("connString").ToString)
It gives me this error after I log in through Membership class:
Cannot open database "MyProject" requested by the login. The login failed.
Login failed for user 'My-PC\Myuser'.
I am not sure what's going on?
Edit: If i don't use Membership class, I can use the database fine.. but when after I login using the membership class, it stops to work..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试从 web.config 中删除“connString”并使用“LocalSqlServer”连接字符串(它在 machine.config 中定义):
Try removing "connString" from web.config and using "LocalSqlServer" connection string instead (it is defined in machine.config):
我也遇到了这个问题,我注意到如果我将数据库的所有者更改为“My-Pc\MyUser”(通过EXEC sp_changedbowner 'My-Pc\MyUser'),它确实可以工作上面指出了。
您也可以尝试在数据库上运行此命令:
如果您希望 MyUser 和 MyUser2 能够访问您的数据库,这当然很有用。 当我必须使用 MyUser2 凭据执行 aspnet_regsql.exe 时,我遇到了这种情况(因为我的数据库的所有者是 ASPNET,它没有登录/运行功能)。
希望这对某人有帮助:)
I also encountered this problem, and I noticed that it does indeed work if I changed the owner of the database to 'My-Pc\MyUser' (via EXEC sp_changedbowner 'My-Pc\MyUser') as pointed out above.
You might also try running this on your database:
This is certainly useful if you want MyUser AND MyUser2 having access to your database. I encountered this scenario when I have to execute aspnet_regsql.exe using MyUser2 credentials (as the owner of my database is ASPNET, which does NOT have login/runas capabilities).
Hope this helps someone :)
您可能需要确保运行 Web 服务器的用户具有对 db 文件和目录的读/写访问权限。
You'll probably need to make sure that the user the web server is running as has read/write access to the db file and directory.
确保 My-Pc\MyUser 具有访问“MyProject”数据库的适当权限。 对于我的本地项目运行的测试环境,我通常将自己指定为我想要访问的数据库的数据库所有者。 也就是说,如果我是唯一访问它的用户。 您可以通过运行 EXEC sp_changedbowner 'My-Pc\MyUser' 来执行此操作。 显然,您希望为您的生产环境提供一个具有有限访问权限的单独帐户。
Make sure My-Pc\MyUser has access appropriate permissions to 'MyProject' database. For the test environment that my local projects run on, i generally assign myself as the database owner to the database i want to access. That is if i am the only user accessing it. You can do so by running EXEC sp_changedbowner 'My-Pc\MyUser'. Obviously, you want to dedicate a separate account with limited access for your production environment.