0

На сервере asp мы получаем ошибку для SQL Server после выполнения ExecuteScalar, ExecuteReader и ExecuteNonQuery, как показано ниже. Ошибка будет возникать только иногда, ее не видно всегда. Итак, кто-нибудь знает, почему возникает эта ошибка? Как его решить?Ошибки для подключения SQL Server в asp-сервере

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.TdsExecuteSQLBatch(String text, Int32 timeout, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
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 WinMsg.Page_Load(Object sender, EventArgs e)

+0

убедитесь, что у вас есть действительная строка подключения. и разрешение доступа. –

+0

@Ravi Он говорит, что получает эту ошибку после успешных вызовов в базу данных. Я не могу себе представить, что они изменяют строки подключения и разрешают доступ во всех случаях. – jadarnel27

+0

Строка подключения правильная, потому что ошибка возникает всего несколько раз. –

ответ

0

Вы упомянули DataReader: пожалуйста, убедитесь, что вы закрыли его правильно. Я подозреваю, что он все еще открыт и предотвращает дальнейшие операции с базой данных.

От MSDN:

While the SqlDataReader is in use, the associated SqlConnection is busy serving the SqlDataReader. While in this state, no other operations can be performed on the SqlConnection other than closing it. This is the case until you call the SqlDataReader.Close method. If the SqlDataReader is created with CommandBehavior set to CloseConnection, closing the SqlDataReader closes the connection automatically.

Также, пожалуйста, убедитесь, что SqlConnection объекта закрыты и утилизировать после использования.