简体   繁体   中英

How do I grant access to my SQL Server Express database to a specific user with Visual Studio 2008 tools?

I'm trying to access an SQL Server Express database out of an ASP.NET HTTP request handler.

The handler is run under ASPNET account and uses "integrated security" in the SQL connection string and so I get an error message saying that login for ASPNET account failed and so I can't access the database.

This seems to be a very common problem and most answers say "grant access to you database to user ASPNET ".

I only have Visual Studio 2008 and I can't find how to change access permisssions for a database. Specifically I use Tools->Server Explorer and I can see all the tables in the database but can't find how to change access permissions.

How do I change access permissions to my database using tools shipped within Visual Studio 2008?

One option is getting the tools for SQL Express would be a good idea—thus getting SQL Server Management Console Express Edition, or just install the SQL Server Management tools (eg. from SQL Server Developer Edition). Then you have the full GUI (including ability to enter and generate SQL).

The other option is to use SQL to do it:

  1. Use CREATE LOGIN to add the login to the SQL Server instance.
  2. Use CREATE USER to add login to the target database.
  3. Use SP sp_addrolemember to assign roles.

Eg. (IIS AppPools is a group of App Pool Identities on system Dev1 being assigned generic read and write data access to the current database):

CREATE LOGIN [DEV1\IIS AppPools] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
CREATE USER [DEV1\IIS AppPools] FOR LOGIN [DEV1\IIS AppPools]
GO
EXEC sp_addrolemember N'db_datareader', N'DEV1\IIS AppPools'
GO
EXEC sp_addrolemember N'db_datawriter', N'DEV1\IIS AppPools'
GO

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