1

I am trying to publish a MVC 4.0 project on IIS 7.0 using SQL Server 2008 R2. I use 'Windows Authentication' and my connection string is

   <add name="PFTMEntities" connectionString="metadata=res://*/PFModel.csdl|res://*/PFModel.ssdl|res://*/PFModel.msl;provider=System.Data.SqlClient;provider connection string=&quot; data source=DEW-PC\SQLEXPRESS;initial catalog=PFTM;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;persist security info=True;&quot;" providerName="System.Data.EntityClient" />

When I build this project and run from VS'12 then it doesn't give any Exception but when I going to publish this project from local server that time it gives following exception

enter image description here

mgsdew
  • 729
  • 1
  • 8
  • 27

2 Answers2

0

Three scenarios depending on your ASP.NET application

  1. (not recommended due to performance) Your ASP.NET uses Windows Authentication, and those users who logs in have access to the MS SQL database

    In this case, you can use impersonation to use the same credentials as the log in user to connect to the database

<configuration>
  <system.web>
    <authentication mode="Windows"/>
    <identity impersonate="true"/>
  ...
  </system.web>
</configuration>
  1. (Recommended) Your ASP.NET is running as NetworkService or a user with limited privileges. Both your web server and database is on the same computer or the same domain

    Grant the account that your ASP.NET is using (e.g. NetworkService) login permission on the MS SQL database

    If your web server and database is on different computer, you'll have to grant login and access to the web server (using the following commands) and place the domainName\WebServerMachineName$ in a database role

exec sp_grantlogin 'domainName\WebServerMachineName$'
exec sp_grantdbaccess 'domainName\WebServerMachineName$'
  1. (Recommended) Your ASP.NET is running as AppPoolIdentity, and must NOT be changed to other account OR both of the above does not apply

    You will have to enable mixed authentication on your MS SQL Server and switch to using username and password for your connection string

Source: http://msdn.microsoft.com/en-us/library/ff647396.aspx

Jeow Li Huan
  • 3,758
  • 1
  • 34
  • 52
  • I try your 1st solution..but still doesn't work... I know this project perfectly run when I give 'Username' & 'Password' in SQL Server...but I want to run this project on 'Windows Authentication Mode' – mgsdew Oct 18 '14 at 17:14
  • Check your config against the following, and do a IIS restart and see if it works http://stackoverflow.com/questions/21891605/getting-iis-to-impersonate-the-windows-user-to-sql-server-in-an-intranet-environ – Jeow Li Huan Oct 19 '14 at 04:15
-1

There are several aspects of the database configuration on the website may cause the problem.

  1. Does the server use the Express version or formal version of SQL Server? You may try to change "data source=DEW-PC\SQLEXPRESS" to "data source=.".

  2. Does the SQL Server allow Network_Service to access the PFTM database? You need to create a login name in SQL Server 2008 R2 for Network_Service , and create a user in the PFTM database.

  • I already try first condition, but doesn't work here.. :( and I know second condition work properly. but I need to work this project on 'Windows Authentication Mode' – mgsdew Oct 18 '14 at 17:11