2009-05-01 8 views
26

Ho diverse applicazioni ASP.NET distribuite in una farm di 4 macchine Windows 2003. Ogni applicazione utilizza un pool di app e una directory virtuale separati in IIS. Si basano molto sulle sessioni che sono persistenti out of process su un singolo SQL Server 2000 (<sessionstate mode="sqlserver" ... />). Le applicazioni sono compilate su .NET 3.0 ma .NET 3.5 SP1 è installato sui server.Problemi di connessione con SQL Server nelle applicazioni ASP.NET che utilizzano lo stato di sessione out-of-process

Ogni server Web riceve circa 10 richieste al secondo. Ogni tanto ricevo alcune eccezioni in tronchi:

System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) 
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) 
    at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket() 
    at System.Data.SqlClient.TdsParserStateObject.ReadBuffer() 
    at System.Data.SqlClient.TdsParserStateObject.ReadByte() 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) 
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 
    at System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) 

o altro:

System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) 
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParserStateObject.WriteSni() 
    at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode) 
    at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush() 
    at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) 
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 
    at System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) 

o ancora un altro:

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) 
    at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket() 
    at System.Data.SqlClient.TdsParserStateObject.ReadBuffer() 
    at System.Data.SqlClient.TdsParserStateObject.ReadByte() 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 
    at System.Data.SqlClient.SqlDataReader.get_MetaData() 
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteReader() 
    at System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) 

Questi errori si verificano un paio di volte al giorno per un periodo di circa 1-2 minuti e poi scomparire. Qualcuno ha riscontrato problemi del genere? Cosa potresti suggerirmi di fare per rintracciare ulteriormente il problema? Per me sembra più un problema di rete che un'applicazione. Potrebbero essere alcune impostazioni su SQL Server che non possono gestire così tante connessioni simultanee? Ogni suggerimento sarà molto apprezzato.


UPDATE:

Ho risolto il problema eseguendo aggiornamenti importanti per l'applicazione al fine di ridurre il numero e le dimensioni degli oggetti essere immagazzinate nella sessione.

risposta

14

Gli errori di livello di trasporto sono spesso collegati alla connessione a SQL Server in corso di interruzione ... di solito in rete.

Timeout Scaduto viene solitamente generato quando una query sql impiega troppo tempo per essere eseguita.

Quindi vorrei risolvere il collegamento al server Sql e quindi monitorare per vedere quali query sono scadute.

Sembra un lavoro SQL in esecuzione, backup? Potrebbe essere bloccare le tabelle o riavviare il servizio.

+0

Grazie per i suggerimenti @Deviant. Controllerò questi e pubblicherei i risultati. –

1

Imposta CommandTimeout = 120 nella stringa di connessione.

provare ad aggiungere un timeout di connessione nel web.config:

<add key="DBConnection" value="server=LocalHost;uid=sa;pwd=;database=DataBaseName;Connect Timeout=200; pooling='true'; Max Pool Size=200"/> 

rispondi se questo funziona ....

+9

Non ti ho dato un segno meno -1 perché credo che dovresti sapere perché la gente ti ha segnato per questa risposta. L'aumento del timeout o persino del pool non risolverà il problema sottostante, aumenterà la scala dell'errore solo se questo errore si ripresenta. – Luke

+1

Non completamente d'accordo. Se è veramente necessario eseguire un singolo comando molto grande, come l'eliminazione di migliaia di righe in una singola istruzione DELETE, è necessario aumentare il Commandtimeout. Normalmente dovresti riconsiderare il problema per evitare questo tipo di situazioni, ma a volte hai bisogno di Commandtimeout superiore ai 30 secondi predefiniti, come in http://stackoverflow.com/questions/11747368/set-command-timeout-in-entity-framework- 4-3 Si dovrebbe anche cercare un altro problema, come i blocchi ... –

+2

Non è possibile impostare il 'CommandTimeout' (cioè il tempo massimo di esecuzione della query) nella stringa di connessione. Nella stringa di connessione, è possibile solo impostare il timeout CONNECTION (ovvero il tempo massimo di attesa per l'apertura di una connessione, che è precedente a qualsiasi esecuzione di query). – BateTech

1

Potrebbe essere il caso in cui la lunghezza della query supera il limite di 65.536 * Dimensione del pacchetto di rete (4KB predefinito).

+0

si applica ai risultati della query o solo alla query inviata al server? – paIncrease

4

Nel mio caso il problema era correlato alla configurazione TCP host (macchina virtuale in VMWare). Dopo una ricerca rapida (some article trovata in Google e MSDN Blogs) ho disattivato il registro di sistema: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\synattackprotect (0) e HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\EnableTCPChimney (0). Ora funziona bene. Naturalmente questa era solo una macchina di prova (rete aziendale non visibile da Internet) e non lo farei in ambiente di produzione ;-)