473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DisconnectedContext was detected

I am trying to match users from one database with users in AD to get
an e-mail address. The program works but right before it exits I get
the following message.

DisconnectedContext was detected
Message: Context 0x1a04b0' is disconnected. Releasing the interfaces
from the current context (context 0x1a0340).This may cause corruption
or data loss. To avoid this problem, please ensure that all contexts/
apartments stay alive until the application is completely done with
the RuntimeCallableWrappers that represent COM components that
liveinside them.

I have read Microsoft's description of what this error means (http://
msdn2.microsoft.com/en-us/library/2c1czate.aspx) but I am not an
experienced programmer and have no clue what "transition into a
disconnected apartment" means.

It definitely has to do with the function as I have striped everything
out and just run this in main:
For x As Integer = 1 To 200
Email = GetUserInfo("Test User", "mail")
Console.WriteLine(x)
Next

Anything less then ~180 and I don't get the message. The Function was
copied (shame on me) from google. I added the Finally clause to see
if disposing would help. The directory path has been changed to
protect the innocent.
Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As
String) As String

Dim sPath As String = "LDAP://xxx/DC=xxx,DC=com"
Dim SamAccount As String = Right(inSAM, Len(inSAM) -
InStr(inSAM, "\"))
Dim myDirectory As New DirectoryEntry(sPath)
Dim mySearcher As New DirectorySearcher(myDirectory)
Dim mySearchResultColl As SearchResultCollection
Dim mySearchResult As SearchResult
Dim myResultPropColl As ResultPropertyCollection
Dim myResultPropValueColl As ResultPropertyValueCollection

Try
'Build LDAP query
mySearcher.Filter = ("(&(objectClass=user)(name=" &
SamAccount & "))")
mySearchResultColl = mySearcher.FindAll()
'I expect only one user from search result
Select Case mySearchResultColl.Count
Case 0
Return "Not Found"
Exit Function
Case Is 1
Return "Multiple"
Exit Function
End Select

'Get the search result from the collection
mySearchResult = mySearchResultColl.Item(0)

'Get the Properites, they contain the usefull info
myResultPropColl = mySearchResult.Properties

'displayname, mail
'Retrieve from the properties collection the display name
and email of the user
myResultPropValueColl = myResultPropColl.Item(inType)
Return CStr(myResultPropValueColl.Item(0))

Catch ex As System.Exception
Return "Null"
'do some error return here.

Finally
mySearcher.Dispose()
myDirectory.Dispose()
End Try

End Function

What am I doing wrong here?

Feb 19 '07 #1
2 4830
No one has any suggestions on this?

Feb 26 '07 #2
Oh come on...there is not one person out there that has a suggestion
on what could be causing this?
Mar 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chandika | last post by:
Hi all, One of my database was suspected, So I try to recover database then it gives this error Err. 823 Torn Page Detected 823, ... 24, spid51 i/o error Torn Page (Detected) during read...
3
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically...
3
by: Laura | last post by:
I've just installed the DB2 Run-time client in a Solaris machine. Then I finnish the installation configuring the connection: 1. machine catalog was OK: ========================== $ db2 catalog...
4
by: Ralf Gross | last post by:
Hi, I installed DB2 V8.1 with fixpak 10, created a new database and can connect to the database. $ db2 connect to mkstest Database Connection Information Database server =...
32
by: Clunixchit | last post by:
How can i read lines of a file and place each line read in an array? for exemple; array=line1 array=line2 ...
0
by: sam.s.kong | last post by:
Hi! When I create or modify an asp file, obvious systax errors are not detected. For example: Sub MySub Response.Write "Hello" End
0
by: Dean Hinson | last post by:
Hello, I have received this message when I exit a program I am working on... DisconnectedContext was detected Message: Context 0x18fbd0' is disconnected. Releasing the interfaces from the...
6
by: Zytan | last post by:
Make a WebBrowser control, and make a bunch of timers / threads that continually call WebBrowser.Document.Write. Eventually, this happens: DisconnectedContext was detected Message: Context...
0
by: Kim Briggs | last post by:
I am developing an BHO/Explorer Bar using Addin Express for Internet Explorer (a framework to get MSHTML/COM Interop newbies like myself off the ground). Target browser is IE7. Occasionally, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.