CREATE DATABASE permission denied in database 'master' - using Web Deploy, EF Code First, Visual Studio - asp.net

Visual Studio 2012 Express, EF5, Code First Migrations, Web Publish.
I am doing a web publish from a Windows 8 Laptop to a Windows Server 2008 R2 web server using Web Deploy from Visual Studio 2012.
The files are uploaded fine. But I get this error:
CREATE DATABASE permission denied in database 'master'
When Code first tries to create the database.
The Web Publishing wizard uses a windows user to login - that user has db_owner permissions on the master database.
Exactly what do I need to do to grant CREATE DATABASE permissions? (or see which user tried to do it - the error doesn't report that for some reason?!).
Thanks.

I've just come across this problem and I resolved it following the instructions here. Effectively, the "IIS APPPool\DefaultAppPool" user must first be added. While adding it, ensure that
as its "Server Roles" it is a "sysadmin".

If you'r running the application from IIS, then IIS APPPOOL\{Your apppool name} is the sql user trying to create the db. If there is no such user in you sql server then create one with the name IIS APPPOOL\{Your apppool name} and give server role dbcreator, public and sysadmin. Now I hope you won't see the error, code first should create the db.

Related

DBResourceFactory issue on production (after publishing)

I have a DBResourceFactory in my ASP.net project and the newly added resources (in the databsae) work fine on localhost but they dont work on production.if i add them to files(resx) they start working fine. but dont work through database. I have reset the IIS too.
This sounds like a db permission problem. You need to grant permission for the Application Pool identity that IIS is using for your website project to access the production database. You can do this in Sql Server Management Studio (if you are using Sql Server that is)

Error when trying to run query using Access remote table

I have an Access database with local and remote tables. The remote tables are linked to a Sql Server Database through an ODBC connection.
When I open the Access database, I can open and view the contents of both the local and remote tables. So this is proof that there should be no problem connecting to the remote tables from an ASP.NET app
Now when I run my ASP.NET app in Visual Studio, I am able to access both the local and remote tables in Access with no problem.
As soon as I put my app into IIS and run the app from localhost, I am only able to access the local tables in the Access file with my code but none of the remote tables! I get the following error when I try: "ODBC--connection to 'FMPOS_live' failed." But remember, I have no problem opening the remote tables from Access directly but I can't access them from my app running in IIS for some reason.
Is there a permission somewhere that depending on who or what is accessing the Access file, determines whether that process can use the remote tables??
When running from Visual Studio you are using your own credentials to connect to the SQL server.
When running from IIS you are using either ApplicationPoolIdentity, Network Service, or Local System depending on configuration of the application pool. You would need to allow login and read privileges to whichever account the website is running under.
In the case of running from VS it's probably working because you're probably a sysadmin on the SQL server.
Try checking what user is running "w3wp.exe" in the task manager.
In the case of ApplicationPoolIdentity the username you're looking for will be IIS APPPOOL\NameOfApplicationPool.
The problem was the application pool identity. Access wasn't allowing access to it's remote tables by the default process ApplicationPoolIdentity Identity. I changed the identity to my windows user login and it worked!
Instructions:
1. Go to the Application Pool for your website
2. Click on it and select Advanced Settings
3. Under Process Model Identity, choose Custom Account and type your username and password for your windows login.

Update database feature not working in Publish Web dialog in Visual Studio 2012

I'm developing an ASP.NET Web Forms application under Visual Studio 2012. I'm using Web Deploy and Publish Web dialog for application deploy. I'm trying to deploy a database schema using the Update database feature. I entered a connection string pointing to remote SQL Server. If I click the "Test connection" button Visual Studio says test connection is succeeded.
Then I go to Preview tab and click the Preview database link.
And in the opened window I have the message
Web deployment task failed. (Could not generate deployment script.
Unable to connect to target server. Learn more at:
http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXECUTING_METHOD.)
Other project files are deployed normally. I'm able to connect to SQL Server using SQL Server Management Service. But why the database could not be updated? I tried to disable server firewall - with no luck.
Visual Studio Professional 2012
SQL Server 2012
Web Deploy 3.0
Update
All works fine if I use SQL Server Authentication with the sa login instead of Windows Authentication in connection string for DatabaseEntitiesRaw. But Windows Authentication works fine for SSMS, and I want to use it since I'm deploying only from computers within my company's domain. Is it true that dbDacFx doesn't work with Windows Authentication?
Deploy script runs from AUTHORITY\LOCAL SERVICE user, so you have to add this user to SQL server. Do not foget to add db_owner role for the user.

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:
Use CREATE LOGIN to add the login to the SQL Server instance.
Use CREATE USER to add login to the target database.
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

Problem using IIS 7 and SQL SERVER 2008

I have problem using IIS 7 and SQL Server 2008. When I trying to show my website using IIS as webserver I get the message "[SqlException (0x80131904): Login failed for user..."
When I using the webserver included in Visual Studio 2010 to show same website there is no problem to access the database.
Why is it working with VS2010 webserver but not with IIS?
I will try to guess:
You're using windows authentication to access the SQL SERVER and the user of the site's application pool (if you're not impersonating) doesn't have necessary permissions.
If I'm not wrong, the default application user for application pools on IIS7 is NETWORKSERVICE so 2 valid options would be
You give necessary permissions to this user
You change the app pool's user to any with necessary permissions
Add the IIS Group in the SQL SERVER "IIS_WPG" to have access to the DataBase.

Resources