I have a problem using Entity Framework and COM+. The architecture is this:
- A windows service calls four methods of a COM, every n minutes.
- COM+ then calls the corresponding methods on a Business Layer.
- Business Layer calls DAL. DAL then returns a list to Business Layer. This is done by calling a
.ToList()
When I try running the service, the DAL methods return a timeout inner exception. When I try to view the table from Enterprise Manager, it returns a timeout as well! From what I 've seen, the SELECT
statements block the other connection instances.
Has anyone else experienced similar problems?
P.S. I cannot post any code yet because I am开发者_Python百科 not at my work... Will do so tomorrow.
Well, as it seems, Entity Framework didn't have to do with any of the above. As it turns out, the problem was within COM+. I should have ended each method of COM+ with ContextUtil.SetComplete(). Apparently, I didn't do that so the transaction stayed active and after the first few calls, it locked my db.
e.g.
Using MyEntity As New EntityObject
MyEntity.Connection.Open()
Dim rows = From tbl In MyEntity.MyTable _
Select tbl
list = rows.ToList
End Using
ContextUtil.SetComplete()
Please note that if an exception occurs, you should place a ContextUtil.SetAbort(). I should also like to note that the above code is mixed. It's part of my DAL layer and part of my COM+. I just put it like that to make the example more clear...
精彩评论