[英]iis 7.5 application pool problems failing
I have been working on our website and every once in a while we get weird results. 我一直在我们的网站上工作,有时我们会得到奇怪的结果。 The IIS application pool seems to have problems and the db connection fails.
IIS应用程序池似乎有问题,并且数据库连接失败。 I check the DB and all is fine & if I run the sql statement in the DB its lightning fast.
我检查了数据库,一切都很好,并且如果我在数据库中运行sql语句,它的运行速度很快。 Then every person after that first failure will fail to connect to the DB afterwards until I recycle the IIS application pool.
然后,在第一次失败之后,每个人之后都将无法连接到DB,直到我回收IIS应用程序池为止。
I am checking my code for memory leaks right now. 我正在检查我的代码是否存在内存泄漏。
I did notice when I logged in and started working at 5 am this morning the memory usage was at 77% and no one is logged in right now, prior to me stress testing the system. 我确实注意到,当我登录并于今天早上5点开始工作时,内存使用率为77%,并且在我对系统进行压力测试之前,现在没有人登录。 Now I do know this box has sql server on it, so that will consume as much memory as possible.
现在,我确实知道此框上有sql server,因此将占用尽可能多的内存。 I am wondering if we should add more memory and limit sql to what it has now, and allow the new memory to be used for IIS.
我想知道我们是否应该添加更多内存并将sql限制为现在所拥有的内存,并允许将新内存用于IIS。
Is anyone an IIS guru, specifically with the IIS Application Pool settings? 是否有人是IIS专家,特别是IIS应用程序池设置的专家?
here is my code i am using to call the database: 这是我用来调用数据库的代码:
dim strU_TmRecord5 as string
strU_TmRecord5 = "Some sql query..."
strSaveSuccessful = exExecuteNonQuery(strU_TmRecord5, "ConnectDBSettings", strUser)
Public Shared Function exExecuteNonQuery(ByVal sqlString As String, ByVal strConnName As String, Optional ByVal strUser As String = "") As Object
Dim strConnString As String = ConfigurationManager.ConnectionStrings(strConnName).ConnectionString
Dim sqlConnection1 As New SqlConnection(strConnString)
Dim returnValue As String = "FAIL"
Dim cmd As New SqlCommand
' NonQuery does not return any data
Try
cmd.CommandText = sqlString
cmd.CommandType = Data.CommandType.Text
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.ExecuteNonQuery()
returnValue = "SUCCESS"
sqlConnection1.Close()
Catch ex As Exception
returnValue = "FAIL"
If sqlConnection1 IsNot Nothing Then
sqlConnection1.Close()
End If
Finally
End Try
Return returnValue
End Function
here is code for DataReader: 这是DataReader的代码:
Dim drDataReader1 As SqlDataReader = Nothing
Dim strGetMgrInfo as string = "sql stuff to get mgr info"
Try
Dim drDataReader As SqlDataReader
ddlMgrName.Items.Clear()
drDataReader = Utilities.exExecuteDataReader(strGetMgrInfo, "DBConnect", strUser)
If drDataReader.HasRows = False Then
lblError1.Visible = True
lblError1.Text = "Invalid Employee Info"
Else
While drDataReader.Read()
ddlMgrName.Items.Add(New ListItem(drDataReader(0).ToString.Trim, drDataReader(1).ToString.Trim))
End While
drDataReader.Close()
End If
Catch ex As Exception
Finally
End Try
Public Shared Function exExecuteDataReader(ByVal sqlString As String, ByVal strConnName As String, Optional ByVal strUser As String = "") As SqlDataReader
Dim returnValue As SqlDataReader = Nothing
' Scalar gets 1st column of 1st row no matter how many records are returned.
Dim strConnString As String = ConfigurationManager.ConnectionStrings(strConnName).ConnectionString
Dim sqlConnection1 As New SqlConnection(strConnString)
sqlConnection1.Open()
Dim cmd As New SqlCommand
exExecuteDataReader = Nothing
cmd.CommandText = sqlString
cmd.CommandType = Data.CommandType.Text
cmd.Connection = sqlConnection1
Try
returnValue = cmd.ExecuteReader(Data.CommandBehavior.CloseConnection)
Return returnValue
Catch ex As Exception
If sqlConnection1 IsNot Nothing Then
sqlConnection1.Close()
End If
End Try
End Function
Running IIS and SQL on the same box for any production systems is a bad idea. 对于任何生产系统,在同一个盒子上运行IIS和SQL是一个坏主意。 SQL can be capped in its memory use.
SQL可以限制其内存使用量。 IIS not so much (you can give it a limit but it will just whack your application every time it goes over, which is probably not what you want).
IIS并不是很多(您可以给它一个限制,但是每次使用它时,它只会重击您的应用程序,这可能不是您想要的)。
A memory leak is the first thing to check, but you should also make sure you're not leaking database connections. 内存泄漏是要检查的第一件事,但您还应确保不泄漏数据库连接。 You MUST close/dispose those, or you will experience exactly what you are seeing.
您必须关闭/处置这些物品,否则您将完全体验到自己所看到的。
Also, the DataReader
returned from the second query function requires the connection, so you can either return a disposable object that holds both the DataReader
and the SqlConnection
and rely on the caller to dispose of that I don't recommend this), or you can copy the data out from the DataReader
into an array of custom objects (like an ORM system), a DataTable
object, or some other kind of object. 另外,从第二个查询函数返回的
DataReader
需要连接,因此您可以返回一个同时容纳DataReader
和SqlConnection
的一次性对象,并依靠调用者来处理(我不推荐这样做),或者您可以将数据从DataReader
复制到自定义对象数组(如ORM系统), DataTable
对象或某种其他类型的对象中。 The second method is preferable, because it captures the data as quickly as possible and then releases the connection for other requests to use. 第二种方法是可取的,因为它会尽快捕获数据,然后释放连接以供其他请求使用。 The first method would only be used in situations where there is so much data being returned that it cannot be reasonably held in memory.
第一种方法仅在返回的数据太多而无法合理地保存在内存中的情况下使用。 Even in that case, though, passing in some kind of processing delegate and having that process each row within the function is probably a better design.
即使在这种情况下,传递某种处理委托并对该函数中的每一行进行处理也可能是更好的设计。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.