ASP.NET ASPNETDB.MDF 无法打开数据库

发布于 2024-07-30 03:21:34 字数 892 浏览 2 评论 0原文

我正在使用会员资格类别进行用户管理,它创建了一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

海之角 2024-08-06 03:21:35

尝试从 web.config 中删除“connString”并使用“LocalSqlServer”连接字符串(它在 machine.config 中定义):

Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString)

Try removing "connString" from web.config and using "LocalSqlServer" connection string instead (it is defined in machine.config):

Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString)
郁金香雨 2024-08-06 03:21:35

我也遇到了这个问题,我注意到如果我将数据库的所有者更改为“My-Pc\MyUser”(通过EXEC sp_changedbowner 'My-Pc\MyUser'),它确实可以工作上面指出了。

您也可以尝试在数据库上运行此命令:

exec sp_grantlogin 'My-PC\MyUser2'

如果您希望 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:

exec sp_grantlogin 'My-PC\MyUser2'

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 :)

伴我心暖 2024-08-06 03:21:34

您可能需要确保运行 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.

ゝ偶尔ゞ 2024-08-06 03:21:34

确保 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文