3

我一直在 Visual Studio 中使用我的网站(ASP.NET MVC),但现在我想将它托管在我的服务器上。我从 Visual Studio 发布到要使用的网络共享。该服务器正在运行 Windows Home Server、IIS 6 和 SQL Server 2008 R2 (express)。

在 Microsoft SQL Server Management Studio 中,我附加了数据库并确保用户 IUSR_SERVER 是数据库的所有者。我还确保用户网络服务具有访问权限。

该网站在 IIS 中配置为以 IUSR_SERVER 匿名运行。我已授予文件系统中 IUSR_SERVER 和网络服务的写入和读取权限,并确保没有任何内容是只读的。

web.config 有这个连接字符串:

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

但是,我无法浏览我的网站。我只收到此错误:

“/”应用程序中的服务器错误。

用户无权执行此操作。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:用户无权执行此操作。

源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪:

[SqlException (0x80131904): 用户无权执行此操作。]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194

感觉我什么都试过了。非常感谢您在这方面的帮助。

编辑:

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.
4

4 回答 4

2

原来问题在于我的 DataContext 正在使用它自己的连接字符串,它不在 web.config 中。因此,它从未更改,无法建立连接。我更改了我的代码,以便我的 datacontext 使用来自 web.config 的字符串并且它有效:)

于 2010-06-06T09:48:39.223 回答
1

您是否已验证 IUSR_Server 帐户对文件系统中的 SQLExpress 数据库具有完全访问权限?

您还可以尝试让 IIS 中的应用程序池作为 IUSR_Server 运行(应用程序在其自己的应用程序池中运行,对吧?)。然后将匿名用户的网站安全更改回默认设置。执行此操作时,请确保 IUSR_Server 帐户是 IIS_WPG 组的一部分,这将为该帐户提供在应用程序池中模拟的所有正确权限。

于 2010-06-01T20:43:06.967 回答
1

权限不是由用户标识,而是由 SQL Server 为登录而持有的内部标识。由于这是两台服务器,因此两台机器上登录名的内部 ID 不同。

当您跨服务器移动数据库时,您必须修复用户登录,因为他们成为孤立的。新服务器上的内部 ID 不同,因此您可以通过运行以下 TSQL 命令来修复用户登录:

EXEC sp_change_users_login 'Auto_Fix', 'IUSR_Server'

数据库中有一个用户,但服务器上也必须有一个登录名。您必须检查它们是否都存在才能解决问题(如果它与数据库用户是孤儿有关)

于 2010-06-01T20:45:20.787 回答
0

在以下第 3 行

线程信息:
线程 ID:1
线程帐户名:SERVER\USER

<-- 什么是 SERVER\USER,是您的 IUSER 还是网络服务?如果是网络服务,(通常是应用程序池的 ID),你的这个线程帐户名应该可以访问你的 Sql 服务器数据库。理想的解决方案是通过提供显式凭据来更改配置,或者确保 Thread 帐户名具有对数据库的完全访问(读/写)访问权限。

于 2010-06-06T10:01:39.157 回答