Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 79845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:12:35+00:00 2026-05-10T21:12:35+00:00

What I’m trying to do is run the same SQL select on many Oracle

  • 0

What I’m trying to do is run the same SQL select on many Oracle databases (at least a dozen), and display the output in a Gridview.

I’ve hacked together something that works but unfortunately it’s very slow. I think its exacerbated by the fact that at least 1 of the dozen databases will invariably be unreachable or otherwise in an error state.

As well as being slow I can’t help thinking it’s not the best way of doing it, nor very ‘.NET’ like.

I’ve written something similar in the past as a simple loop in PHP that just connects to each db in turn, runs the sql and writes another <tr>, and it works at least twice as fast, for a given query. But I’m not really happy with that, I’d like to improve my knowledge!

I’m learning C# and ASP.NET so please excuse the horrible code 🙂

public void BindData(string mySQL)     {         OracleConnection myConnection;         OracleDataAdapter TempDataAdapter;         DataSet MainDataSet = new DataSet();         DataTable MainDataTable = new DataTable();         DataSet TempDataSet;         DataTable TempDataTable;         string connectionString = '';         Label1.Visible = false;         Label1.Text = '';          foreach (ListItem li in CheckBoxList1.Items)         {             if (li.Selected)             {                 connectionString = 'Data Source=' + li.Text + '';                 connectionString += ';Persist Security Info=True;User ID=user;Password=pass;Unicode=True';                 myConnection = new OracleConnection(connectionString);                 try                 {                     TempDataAdapter = new OracleDataAdapter(mySQL, myConnection);                     TempDataSet = new DataSet();                     TempDataTable = new DataTable();                     TempDataAdapter.Fill(TempDataSet);                     TempDataTable = TempDataSet.Tables[0].Copy();                     /* If the main dataset is empty, create a table by cloning from temp dataset, otherwise                      copy all rows to existing table.*/                     if (MainDataSet.Tables.Count == 0)                     {                         MainDataSet.Tables.Add(TempDataTable);                         MainDataTable = MainDataSet.Tables[0];                     }                     else                     {                         foreach (DataRow dr in TempDataTable.Rows)                         {                             MainDataTable.ImportRow(dr);                         }                     }                 }                 catch (OracleException e)                 {                     Label1.Visible = true;                     Label1.Text = Label1.Text + e.Message + ' on ' + li.Text + '<br>';                  }                 finally                 {                     if (myConnection != null)                     {                         myConnection.Close();                         myConnection = null;                     }                     TempDataSet = null;                     TempDataAdapter = null;                     TempDataTable = null;                  }             }         }         GridView1.DataSourceID = String.Empty;         if (MainDataSet.Tables.Count != 0)         {         GridView1.DataSource = MainDataSet;             if (GridView1.DataSource != null)             {                 GridView1.DataBind();             }         }     }     protected void Button1_Click(object sender, EventArgs e)     {         BindData(TextBox1.Text);     } 

Thanks!

UPDATE: The SQL code varies, for testing I have used very simple queries such as select sysdate from dual or select name from v$database. In eventual use, it will be much more complicated, the idea is that I should be able to run pretty much anything, hence the BindData(TextBox1.Text)

UPDATE: The reason for connecting to many databases from the ASP.NET code rather than a stored proc on one or all dbs, or replicating to one db, is twofold. Firstly, the dbs in question are frequently updated replicas of several similar production environments (typically development, testing and support for each client), so anything done to the actual dbs would have to be updated or redone regularly as they are reloaded anyway. Secondly, I don’t know in advance what kind of query might be run, this form lets me just type e.g. select count (name) from dbusers against a dozen databases without having to first think about replicating the dbusers table to a master db.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:12:35+00:00Added an answer on May 10, 2026 at 9:12 pm

    If you run the DataAdapter.Fill method on a DataTable object the table will be updated with the results from the query. So instead of creating new DataTable and DataSet objects and then copying the DataRows manually you can just add rows to the same table.

    Try something like this (in untested C# code):

    public void BindData(string mySQL) {   OracleConnection myConnection;   // Empty connection string for now   OracleDataAdapter MainDataAdapter = new OracleDataAdapter(mySQL, '');    DataTable MainDataTable = new DataTable();   string connectionString = '';   Label1.Visible = false;   Label1.Text = '';    foreach (ListItem li in CheckBoxList1.Items)   {     if (li.Selected)     {       connectionString = 'Data Source=' + li.Text + '';       connectionString += ';Persist Security Info=True;User ID=user;Password=pass;Unicode=True';       MainDataAdapter.SelectCommand.Connection.ConnectionString = connectionString       try       {         MainDataAdapter.Fill(MainDataTable);       }       catch (OracleException e)       {         Label1.Visible = true;         Label1.Text = Label1.Text + e.Message + ' on ' + li.Text + '<br>';       }     }   }   GridView1.DataSourceID = String.Empty;   GridView1.DataSource = MainDataTable;   GridView1.DataBind(); } 

    I did the following changes:

    • Created one data adapter and assigned it a select command using your mySQL query
    • Gave the connection an empty connection string
    • Created a data table object and removed the data sets (you only need them if your query returns several rows)
    • Changed you loop to just set the connection string of the SelectCommand (you may have to change this to replacing the SelectCommand with a new one)
    • Removed the connection.Close() calls. The DataAdapter does this automatically.

    And thats it. If your databases are offline you will still experience slowdowns, but at least the code is simpler and faster since you don’t have to copy all the rows between your tables.

    One more thing. You can probably set a timeout for the connection in the connection string. Try to lower this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Trying to measure programmers performance with bug reports is a… May 11, 2026 at 3:04 pm
  • added an answer Silly question, but do you actually have IIS installed on… May 11, 2026 at 3:04 pm
  • added an answer There's no other way of executing arbitrary C# source code… May 11, 2026 at 3:04 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
What I want to achieve is this. I want to give the user the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.