0

I have an sql database running locally. In visual studio, server explorer, I am connected to this database so I am sure of the validity of the connection string which is :

Data Source=MyMachineName;Initial catalog=MyDBName;Integrated Security=True

However when I am trying to access to the db from my application i am getting the following exception in my browser :

System.Data.SqlClient.SqlException : Authorization CREATE DATABASE denied in database 'master'

For information, I am running my application through my iis server.

Thanks in advance for your help

user2443476
  • 1,935
  • 9
  • 37
  • 66
  • 2
    Possible duplicate of [CREATE DATABASE permission denied in database 'master' (EF code-first)](http://stackoverflow.com/questions/11231934/create-database-permission-denied-in-database-master-ef-code-first) – Daniel Dec 27 '16 at 09:43

1 Answers1

0

Your IIS site by default is running under ApplicationPoolIdentity user, which does not have rights to your system. You can change that user to your user from IIS Manager. First find which "application pool" is your application running on, then go to that application pool in the "Application Pools", right click then select "Advanced Settings", and under "Process Model" you will find the "Identity" record. enter image description here

P.S. If you haven't changed the application pool of your site just edit the "DefaultAppPool"

Ivelin Ivanov
  • 148
  • 3
  • 14
  • Ok but what do I have to do then. When I am trying to define a custom account it aks me username and password. How can I relate it with my previous connection string – user2443476 Dec 27 '16 at 12:24
  • "Integrated Security" means that the entityframework data adapter will try to connect to the database with the current windows user account, and database server will give rights to the database that are set to this account. To summarize, if IIS site runs under some account, then that account will be used to connect with the database. – Ivelin Ivanov Dec 27 '16 at 13:21
  • If you want to use other user, you can remove the "Integrated Security" setting, and add custom username and password: `Data Source=MyMachineName;Initial catalog=MyDBName;Integrated Security=False, User ID=, Password=` – Ivelin Ivanov Dec 27 '16 at 13:22
  • Ok so suppose that I want to use current windows account. So I am letting the integrated security to true in my connection string. But what do I have to do with my application pool to tell it to use my windows account. – user2443476 Dec 27 '16 at 13:30
  • change the account of the application pool with your account as I showed you in the answer. Under the "Identity" you just need to select "custom account" and enter your credentials. – Ivelin Ivanov Dec 28 '16 at 11:04
  • hope this helps you. – Ivelin Ivanov Dec 28 '16 at 16:36