2010-06-18 101 views
1

我正在開發一個訪問SQL Express數據庫的Web服務,它在Visual Studio主機中工作得很好,但是當我將它部署到IIS 7.5時,我得到了這個異常。IIS 7.5下的SQL Express

請幫幫我。

堆棧跟蹤:

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed. 
    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.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) 
    --- End of inner exception stack trace --- 
    at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) 
    at System.Data.EntityClient.EntityConnection.Open() 
    at System.Data.Objects.ObjectContext.EnsureConnection() 
    at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) 
    at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() 
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) 
    at WSCinema.CinemaService.Movie() in D:\Documents\My Dropbox\Projects\sd.v0910\trab3\code\WSCinema\CinemaService.asmx.cs:line 46 

回答

2

,由於需要寫訪問到你的數據庫文件(MDF)存儲在App_Data文件夾在IIS中您的應用程序的應用程序池運行的帳戶。例如。如果應用程序池配置爲以網絡服務運行,則爲App_Data文件夾上的該帳戶授予權限。

當您在VS主機中運行時,您的應用程序將作爲您有權訪問App_Data的用戶帳戶運行。

+0

標記你的問題導致解決我的問題。 ty =) – fampinheiro 2010-06-18 22:02:33

1

您正在使用RANU,SQL Express用戶實例。在SQL Server 2005 Express Edition User Instances查看更多關於它們的細節。 RANU爲連接到原始SQL Express實例的每個用戶創建一個新實例,並且新用戶實例在用戶憑證下運行。在這種情況下,它會創建下的ASP程序池身份的用戶實例,並試圖創建該用戶實例擊中錯誤:

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer.

所以,如果你堅持使用用戶實例,請確保應用程序池標識在IIS主機上有一個配置文件。但是,如果放棄用戶實例,則會更方便,更簡單,只需直接使用SQL Express實例即可。

+0

謝謝你的問題,爲你投票,這只是一個litle學校的工作,我會放棄用戶實例在我的下一個項目=) – fampinheiro 2010-06-18 22:03:24

+0

typ0:答案沒有問題xD – fampinheiro 2010-06-19 12:44:57