简体   繁体   中英

ASP.NET Membership provider SQL Server Express

Is there any problem with using ASP.NET Membership via SQL Server Express ?

When I use this code :

Roles.AddUserToRole("shah", "Admdin")

I am faced with the error shown below.

Config :

OS : windows 7 64 bit.
SQL Server version: SQL Server Express Edition, Version :9.00.4035.00

connectionString="Data Source=.\sqlexpress;Initial Catalog=MShop;Integrated Security=True" 

The user instance login flag is not supported on this version of SQL Server. The connection will be closed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

 If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable 

automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102 . If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist. If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database. Sql Server Express must be installed on the machine. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.

Yes, you can use membership with SQL Express. I think you do not have your Roles configured correctly in web.config. The error indicates it's trying to create the database, but the database should already exist if you are trying to add a role to a user,

You must create the user first, then add them to the role, if the database doesn't exist then either you didn't create the user first, or your roles are configured to use a database that doesn't exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM