public override void Dispose()
        {
            base.Dispose();
            if (_queryInfo != null)
            {
                _queryInfo.Dispose();
                _queryInfo = null;
            }

            if (_connection != null)
            {
                try
                {
                    _connection.Close();
                }
                catch { }
                _connection = null;
            }
        }
        public SdeFeatureCursor(SdeDataset dataset, ITableClass tc, IQueryFilter filter)
            : base((tc is IFeatureClass) ? ((IFeatureClass)tc).SpatialReference : null,
                   (filter != null) ? filter.FeatureSpatialReference : null)
        {
            try
            {
                if (filter != null && filter.SubFields != "*")
                {
                    filter.AddField(tc.IDFieldName);
                }
                filter.fieldPrefix  = tc.Name + ".";
                filter.fieldPostfix = "";

                Int32 err_no = 0;

                _dataset = dataset;
                if (_dataset == null)
                {
                    return;
                }

                //_connection = _dataset.AllocConnection();
                _connection = new ArcSdeConnection(dataset.ConnectionString);
                if (!_connection.Open())
                {
                    return;
                }

                _queryInfo = new SdeQueryInfo(_connection, tc, filter);
                if (_queryInfo.ErrorMessage != "")
                {
                    Dispose();
                    return;
                }

                //if (Wrapper92.SE_stream_create(_connection.SeConnection, ref _stream) != 0)
                //{
                //    Dispose();
                //    return;
                //}

                _connection.ResetStream();

                // SE_stream_set_state sollte auch aufgerufen werden (siehe mapsde.c von UMN)
                if (Wrapper92.SE_stream_set_state(
                        _connection.SeStream,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_DEFAULT_STATE_ID,
                        CONST.SE_STATE_DIFF_NOCHECK) != 0)
                {
                    Dispose();
                    return;
                }

                if ((err_no = Wrapper92.SE_stream_query_with_info(_connection.SeStream, _queryInfo.SeQueryInfo)) != 0)
                {
                    Dispose();
                    return;
                }

                if (_queryInfo.IsSpatial)
                {
                    SE_FILTER se_filter = _queryInfo.Filter_Shape;
                    if ((err_no = Wrapper92.SE_stream_set_spatial_constraints(_connection.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0)
                    {
                        _errMsg = Wrapper92.GetErrorMsg(_connection.SeConnection, err_no);
                        Dispose();
                        return;
                    }
                }
                else
                {
                    /*
                     * SE_FILTER se_filter = _queryInfo.Filter_Id;
                     * if (Wrapper92.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0)
                     * {
                     *  Release();
                     *  return;
                     * }
                     * */
                }

                if (Wrapper92.SE_stream_execute(_connection.SeStream) != 0)
                {
                    Dispose();
                    return;
                }

                _queryFields = _queryInfo.QueryFields;
                _queryInfo.Dispose();
                _queryInfo = null;
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.StackTrace;
                Dispose();
            }
        }