SqlException: user does not have permission to perform this action

I use my website (ASP.NET MVC) in visual studio, but now I want to host it on my server. I published from visual studio on a network resource that will be used. The server runs Windows Home Server, IIS 6, and SQL Server 2008 R2 (Express).

In Microsoft SQL Server Management Studio, I linked the database and made sure that the user IUSR_SERVER is the owner of db. I also made sure that the Network Service user has access.

The website is configured in IIS to anonymously run anonymously as IUSR_SERVER. I granted write and read access to IUSR_SERVER, as well as Network Service on the file system, and made sure that nothing was read only.

In web.config there is this connection string:

        <connectionStrings>
    <remove name="ApplicationServices" />
  <add name="ApplicationServices" connectionString="Data Source=.\SQLExpress;Integrated Security=True;Initial Catalog=MyDatebase"
   providerName="System.Data.SqlClient" />
     </connectionStrings>

-. :

"/".

. : . .

: System.Data.SqlClient.SqlException: .

:

-. .

:

[SqlException (0x80131904): .]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException , Boolean breakConnection) +4846887 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194

, . .

EDIT:

This is the event in the event viewer:
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 2010-06-05 23:55:08 
Event time (UTC): 2010-06-05 21:55:08 
Event ID: 88a3a76c00a34e21bf6e711b3b3a8f21 
Event sequence: 137 
Event occurrence: 59 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/6893/Root-2-129202466028125000 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\Inetpub\WebPage\ 
    Machine name: SERVER 

Process information: 
    Process ID: 5864 
    Process name: w3wp.exe 
    Account name: SERVER\USER

Exception information: 
    Exception type: SqlException 
    Exception message: User does not have permission to perform this action. 

Request information: 
    Request URL: http://localhost/ 
    Request path: / 
    User host address: 127.0.0.1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: SERVER\USER

Thread information: 
    Thread ID: 1 
    Thread account name: SERVER\USER
    Is impersonating: True 
    Stack trace:    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)     

Custom event details: 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
+3
4

, , DataContext , web.config. . , datacontext web.config, :)

+2

, IUSR_Server SQLExpress ?

IIS IUSR_Server ( ?). . , , IUSR_Server IIS_WPG, .

+1

, , SQL Server . , .

, , . , , TSQL:

EXEC sp_change_users_login 'Auto_Fix', 'IUSR_Server'

, . , ( , )

+1

№ 3

:
   : 1
   : SERVER\USER

<- what is SERVER \ USER, is it your IUSER or network service? if it is a Network Service (usually an application pool identifier), your Thread account name must have access to your Sql server database. The ideal solution is to either change the configuration by specifying explicit credentials, or make sure that the Thread account name has full access (read / write) to your database.

0
source

Source: https://habr.com/ru/post/1748042/


All Articles