Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

DataConnection: "Cannot access a disposed object"

$
0
0

I have a n00b issue here. I am reverse engineering an Access application into a C# Web site; the application accepts search terms and queries multiple database servers on those terms, then compiles all the returned records into a single form. While the Access application uses multiple recordsets to store the returned data from the multiple DB servers, I am collecting the data in one or more datatables.

The problem: when trying to open the connection to the second DB, I get the error message "Cannot access a disposed object. Object name: 'OracleConnection'". Here is how I'm connecting to the first DB:

try
        {
            using (OracleConnection conParts = new OracleConnection(conStrParts))
            {
                conParts.Open();
                da = new OracleDataAdapter(strSQL, conParts);
                da.Fill(ds, "tmpMParts");
            };
        }
        catch (Exception ex)
        {
            errInput.Text += "<br />Error in creating your local MPARTS table. " + ex.Message + "; " + errBk;
            gridMParts.DataSource = ds.Tables["tmpMParts"];
            gridMParts.DataBind();
            goto exitFilter;
        }
        finally
        {
        };

The second DB connection goes like this:

        try
        {
            using (OracleConnection conStarsEdit = new OracleConnection(conStrStars))
            {
                conStarsEdit.Open();
                da.SelectCommand.CommandType = System.Data.CommandType.Text;
                da.SelectCommand.CommandText = strSqlStarsEdit;
                DataTable dtStarsEdit = new DataTable("tmpStarsEdit");
                // Error gets thrown here!
                da.Fill(ds, "tmpStarsEdit");
                if (ds.Tables["tmpStarsEdit"].Rows.Count == 0)
                {
                    goto StarsPublished;
                }
                da.Fill(ds, "tmpMParts");
            };
        }
        catch (Exception ex)
        {
            errInput.Text += "<br />Error in StarsEdit module: " + ex.Message + "; " + errBk + "<br />" + strSqlStarsEdit;
            goto exitFilter;
        }
        finally
        {

        }

What am I doing wrong here? Thanks in advance for your help and insights!


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>