How to handle "create database permission denied in database 'master' in windows authentication exception? - asp.net

I opened "ASP.NET SQL Server Setup Wizard" using the command apsnet_regsql from visual studio 10 command propmpt(Run as Administrator).
In that wizard I selected Windows Authentication instead of Sql Authentication. When I tries to connect to Master Database I am getting the following exception
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 262 and the SqlException message is: CREATE DATABASE permission denied in database 'master'.
Creating the TestDB database
and the SqlException is:
create database permission denied in database 'master' in windows authenticAtion.
I understand that I don't have permission to create database. But how and where can I give permission to do that.
So please help me and give a solution for my problem.Thanks.

You need to login as a user who is a member of the sysadmin or dbcreator roles.

Related

CREATE DATABASE permission denied in database 'master'

I receive this error when trying to login using ipadd/loginpage.aspx. This happens when I try to login on my Local Area Network using a different machine:
CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file E:\StoreDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
You cannot create a database nor attached a database because you have no privileged to do so. Here's my workaround:
First, run the SQL Server Management Studio as "administrator". Then, login to your account. Next, click the Security folder --> click Logins --> choose your account name --> check the properties and verify the status if you have permission to connect to database engine.
I hope it helps you.

How to handle "create database permission denied in database master" in windows Authentication?

I opened "ASP.NET SQL Server Setup Wizard" using the command apsnet_regsql from visual studio 10 command propmpt(Run as Administrator).
In that wizard I selected Windows Authentication instead of Sql Authentication. When I tries to connect to Master Database I am getting the following exception
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 262 and the SqlException message is: CREATE DATABASE permission denied in database 'master'. Creating the TestDB database
and the SqlException is:
create database permission denied in database 'master' in windows authenticAtion.
By the exception I understand that I don't have permission to create database. But how and where can I get permission to do that.
i have SQL Server 2008 in my system which comes as default with Visual Studio 2008 only.
So please help me and give a solution for my problem.Thanks
Obviously the reason why this is happening is because the user does not have the permission in sql sever to do any modification one of the ways to solve it would be to go to security folder chose user select properties might be permissions and make this user a dbadministrator or other advanced role than login with this user and try to create the database
here are couple of articles
http://msdn.microsoft.com/en-us/library/dd568727.aspx
http://msdn.microsoft.com/en-us/library/ms178630(v=sql.90).aspx
http://www.blackwasp.co.uk/SQLChangeOwner.aspx

login failed for user nt/authority

I am trying to deploy my website and wcf runs in my localhost...if i login i.e use db i am gettin this error...Any idea wht the pblm would be ?
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
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.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
Few months ago I had also faced the same kind of problem. This occurred because by default the database connection string uses a trusted connection and When a client is accessing SQL Server via a trusted connection the database you are accessing might have a trusted connection account within the userlist with db_owner rights to the target database.Here are the steps to remove the error.
Here is the SOLUTION for the problem:
Its very simple, just you need to add a new user instead of the previous user for your database.
For example: I had a database named CRM having user crm. I created a new user for my database CRM as kos.
Here are the steps to do so:
Open your SQL Server Management Studio.
Click on the database node and then the Security node->Logins.
For further visit: http://kopila.com.np/login-failed-for-user-in-asp-net.html
This looks to me like you're using Windows Authentication when the account that the ASP net process is running under doesn't have access to the sql server.

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'

I been strugling with this for 2 days now without comming any closer to solution. I have read 20-30 threads alteast and stil can not resolve this.
Please help me out.
I have disable anonymous authentication, enable asp.net impersonation.
I have added <identity impersonate = "true" />
I have added the a user to the security logins that is connected to the database I try to connect to
This is the connectionstring I use:
Data Source=IPTOSERVER;Initial Catalog=Phaeton;User Id=User;Password=Password;
errormessage:
Cannot open database "Phaeton.mdf" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
I was experiencing a similar error message that I noticed in the Windows Event Viewer that read:
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Reason: Failed to open the explicitly specified database. [CLIENT: local machine]
The solution that resolved my problem was:
Login to SqlExpress via SQL Server Management Studio
Go to the "Security" directory of the database
Right-click the Users directory
Select "New User..."
Add 'NT AUTHORITY\NETWORK SERVICE' as a new user
In the Data Role Membership area, select db_owner
Click OK
Here's a screenshot of the above:
The error message you are receiving is telling you that the application failed to connect to the sqlexpress db, and not sql server.
I will just change the name of the db in sql server and then update the connectionstring accordingly and try it again.
Your error message states the following:
Cannot open database "Phaeton.mdf" requested by the login. The login failed.
It looks to me you are still trying to connect to the file based database, the name "Phaeton.mdf" does not match with your new sql database name "Phaeton".
Hope this helps.
If the error message is just
"Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.", then grant
the login permission for 'NT AUTHORITY\NETWORK SERVICE'
by using
"sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'"
else if the error message is like
"Cannot open database "Phaeton.mdf" requested by the login. The login
failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'."
try using
"EXEC sp_grantdbaccess 'NT AUTHORITY\NETWORK SERVICE'"
under your "Phaeton" database.
I liked Jed's solution but the issue with that was every time I built my project in debug mode, it would deploy my database project and removed the user again. so I added this MySQL script to the Post-Deployment script.
it practically does what Jed said but creates the user every time I deploy.
CREATE USER [NT AUTHORITY\NETWORK SERVICE]
FOR LOGIN [NT AUTHORITY\NETWORK SERVICE]
WITH DEFAULT_SCHEMA = dbo;
Go
EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'
You said it worked fine when you were using SQL Express edition. By default express editions create a named instance & run in NT Authority\Network Service.
SQL Server STD by default install a default instance & run in NT Authority\SYSTEM.
Do you have both the full SQL edition & Express edition installed on the same machine?
It could be that somewhere the connection string still refers to the Named instance 'SQLEXPRESS' rather than the default instance created by the full version.
Also where is the connection string defined? In IIS or your code? Make sure that if defined in many places, all point to same SQL instance & database.
Also try looking at the detailed error present in the SQL Server error logs. The error logged in event log are not complete for secuirty reasons. This will also help you to know if the connection was made to the correct SQL Server.
Also make sure that the machine on which SQL is installed is accessible & IIS is trying to access the same machine. In my company sometimes due to wrong name resolution, the query fails since most of our computers have SQL installed & the query lands in the wrong SQL Server.
Make sure that the database exists in the SQL Server. The name displayed under databases in SQL Management Studio should match that in the connection string.
The SQL Server login required is DOMAIN\machinename$. This is the how the calling NT AUTHORITY\NETWORK SERVICE appears to SQL Server (and file servers etc)
In SQL,
CREATE LOGIN [XYZ\Gandalf$] FROM WINDOWS
The Best way is to create a user for your application and assign the permissions that are suitable for that user. Dont use 'NT AUTHORITY\NETWORK SERVICE' as your user it has its own vulnerability and it is a user that has permissions to so many things on the OS level. Stay away from this built in user.
I am using Entity Framework to repupulate my database, and the users gets overridden each time I generate my database.
Now I run this each time I load a new DBContext:
cnt.Database.ExecuteSqlCommand("EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\\NETWORK SERVICE'");
Make sure that the database is created. I got the same error when I applied the migration to the wrong project in the solution. When I applied the migration to the right project, it created the database and that solved the error.

MS SQL update to Integrated Security

For debugging purpose, I backedup one of QA database and restored to local machine. Since it is in my local machine, I just want to connect to it using Integrated Security=True in my asp.net application. But I am getting following error:
Cannot open database "db1" requested
by the login. The login failed. Login
failed for user "DEV-LPTP-1784\ASPNET".
Any thoughts?
Thanks.
Delete and recreate database login you use. After db restore the database user has the same name, but inner SQL Server id is different, so SQL Server thinks that server login "DEV-LPTP-1784\ASPNET" is different than db user "DEV-LPTP-1784\ASPNET"
The user that ASP.NET is running under does not have access to that database. You can either grant that user access via SQL Management Studio, or change your connection string to use a specific username and password.

Resources