OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

Reply
Occasional Contributor
Posts: 5

OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

The below code works just fine in .NET 3.5  But in .NET4.0, it hangs trying to dispose / close the OleDbDataReader.  I've googled and people have seen this before with different providers.   And it usually is because they haven't read all the data.  But in this case, I am reading till there's none left.  Any ideas? I've tried canceling the command.  I'm using 9.4 Technology Integration Tools.   This is the stack where it hangs forever:

mscorlib.dll!System.Runtime.InteropServices.Marshal.ReleaseComObject(object o)    Unknown
System.Data.dll!System.Data.OleDb.OleDbDataReader.Close()    Unknown

using (OleDbConnection connection = new OleDbConnection("Provider=sas.iomprovider.1; SAS Workspace ID=" + wsId))

{

    connection.Open();

    using(OleDbCommand command = new OleDbCommand(String.Format("select * from {0} {1}", txtData.Text, where), connection))

    {

        using (OleDbDataReader reader = command.ExecuteReader())

        {

            //do the reading

            while (reader.Read())

            {

                //read the row

                IList<object> row = new List<object>(reader.FieldCount);

                for (int fieldIdx = 0; fieldIdx < reader.FieldCount; fieldIdx++)

                {

                    object val = reader[fieldIdx];

                }

            }

        } //hangs here!!!

    }

}

Community Manager
Posts: 2,771

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

Make sure that you have the most recent version of the SAS OLE DB providers and the SAS Integration Technologies client.  Here are the links:

SAS Downloads: SAS Integration Technologies Client for Windows

SAS Downloads: SAS Providers for OLE DB

I can't say that this will fix your specific problem, but it's something that you should try. 

Your code snippet doesn't have much context.  I can see that you have some interaction with the a UI component (txtData field) -- make sure that you haven't done anything funky with the threading.  If you spawn a background thread to do work (such as read a lot of data) you'll want to make sure that you don't try to update items on the UI thread without marshalling those calls over first using BeginInvoke() or a similar mechanism.  It's not clear to me whether that might be your issue, but it's something to check.

Chris

Frequent Contributor
Posts: 119

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

To use the OleDB connection on an existing SAS Workspace session you also need to use the SAS ObjectKeeper.

Maybe there is a problem with the correct usage of your ObjectKeeper?

Can you post a full example of your code?

Community Manager
Posts: 2,771

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

might be using my SasHarness project as an example -- if so, there is a use of ObjectKeeper in that project.  See the project on GitHub -- specifically the SasServer.cs file where this is used.

Chris

Occasional Contributor
Posts: 5

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

yup.  I'm using your sas harness as a test case / base.  Works beautifully in .net 2.0 / 3.5 ... not so much in 4.0 Smiley Happy.  I'm downloading the oledb updates you mentioned ... hopefully that helps, and I'll refresh the com dlls referenced in your project..  I'll let you know how it goes.

Also, I was getting an error when creating the workspace in .net 4.0 for the 'bridge' case, but it worked just fine for the 'com' case.  It was a ComException saying "bad address".  Again, scenario worked perfect in .net 2.0

//this line:

_workspace = (SAS.Workspace)obObjectFactory.CreateObjectByServer(

Occasional Contributor
Posts: 5

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

Using the latest OleDB installs seems to have fixed the problems Smiley Happy.  Previously, I think I was using the latest Integration Technologies Client, but with older OleDb adapters.

Also, I'm not using an ObjectKeeper in my final solution (outside of the sas harness demo), but rather using the ObjectPools.  I create a unique logical name based on the hostname, port, connection type, username, and password, and I create a pool using a server def and login def.   Essentially I have a pool of ObjectPools because in my final system there may be many credentials / servers that are used.

Anything I should watch out for?  I have locking to make sure I only create 1 pool per logical name.  I assume pool.GetPooledObject()  and pooledObject.ReturnToPool() are thread safe?

//code snippets

//find the pool based on logical name (not shown) 

//If haven't created it yet, then create pool

pool = ObObjectFactory.ObjectPools.CreatePoolByServer(logicalName, serverDef, loginDef);

//find pool based on logical name (not shown)

//then get workspace out of pool

SASObjectManager.PooledObject obj = pool.GetPooledObject(info.UserId, info.Password, (int)TimeSpan.FromMinutes(1).TotalMilliseconds);

return obj.SASObject;

//return the PooledObject back to pool

            workspace.ReturnToPool();
Community Manager
Posts: 2,771

Re: OleDbDataReader.Close() hangs in .NET 4 for IOMProvider

I don't have much hands-on experience with ObjectPools, but I think your approach should work.  I've looked around internally and don't see any cautions about using those methods on specific/different threads.  Just be careful that if you have any UI interactions that spawn from these that need to happen on an STA thread, you take the proper steps to marshal that call over.

Chris

Ask a Question
Discussion stats
  • 6 replies
  • 534 views
  • 0 likes
  • 3 in conversation