2013-01-05 6 views
5

ASP.NET 4.5のセッション状態モジュールから一貫してエラーが発生しました。SQL Azureデータベースを指すWindows Azure Webロール。セッション状態モジュールはdbcontextを使用しています。 例外は、スタックトレースは:SQL Azureでセッション状態プロバイダ(Entity Framework)から「タイムアウト時間が経過しました。」

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=2; handshake=14993; ---> System.ComponentModel.Win32Exception: The wait operation timed out 
--- End of inner exception stack trace --- 
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) 
at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() 
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() 
at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable) 
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) 
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) 
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) 
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) 
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) 
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) 
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) 
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) 
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.SingleOrDefault[TSource](IEnumerable`1 source) 
at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source) 
at System.Data.Entity.Internal.Linq.InternalSet`1.FindInStore(WrappedEntityKey key, String keyValuesParamName) 
at System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues) 
at System.Web.Providers.DefaultSessionStateProvider.<>c__DisplayClass14.<SetAndReleaseItemExclusive>b__13() 
at Microsoft.Practices.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0() 
at Microsoft.Practices.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func) 
at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) 
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

この問題で私を助けてください。

+0

これまでの回答は見つかりましたか?私はこれらを得ることに賭けているようですが、時折しかありません。 – dreza

+0

おそらく、次のような再試行遅延アルゴリズムがあります。 http://stackoverflow.com/questions/17215377/connection-timeout-in-sql-azure –

答えて

0

SQL Azureは、各データベースが共有サーバーに存在するため、限られたリソースを提供します。つまり、別のクライアントが同じサーバーで長いクエリを実行している場合、アプリケーションのパフォーマンスが低下します。

SQL Azureでの2年間の経験では、DALにいくつかの再試行ロジックを実装して、この種のエラーでアプリケーションがクラッシュしないようにする必要があります。また、各データベースは最大180の同時接続と別の制限(サイズ、管理など)に制限されています。 180以降の各接続は拒否されます。アプリケーションをDoS攻撃から慎重に保護する必要があります。

エンタープライズデータベースでもこの制限を緩和するためのSQL Azureのスタンダードユーザー(あなたまたは私)が利用できるオプション(または構成)はありません。私の会社では、DBAチームとして、トランザクション負荷の高い問題に関するMicrosoft Opsチームの複数のチケットをオープンしました。彼らから受け取った推奨事項は、いくつかのデータベースに沿ったデータのパーティション化、索引付け、再試行ポリシー、 (接続/ログインとクエリ用) - 5回の再試行で設定。大きなSELECT/INSERT/UPDATE/DELETEでは、レコードの長さに応じて1000から10,000までのグループでレコードをセグメント化します。

数年後、データをIaaS(Azure Cloud上でvMとしてホストされているSQL Server)に移行しました。

私のお勧めは、SQL Azureを選択する前に、長所と短所を考えてください!

Luck !!

関連する問題