Backgroundworker + Sql

Hi

I am using a Backgroundworker do load media files from a Sql Server. The user should be able to cancel this operation, but I am not sure how to implement this. If I call backgroundWorker1.CancelAsync(); there is no while-loop I can stop.

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

{

...

XmlReader myReader = XmlReader.Create(sqlCommand.ExecuteXmlReader(), mySettings);

....

}

Thank you



Answer this question

Backgroundworker + Sql

  • snowrabbit

  • JDELUNA

    Thanks for the answer, but what I want to know is, how can I cancel Sql queries If the the transfer rate is low or the Sql Server unreachable, how can I stop the BackgroundWorker (a user can hit cancel to abort the operation)

    public DataTable GetData(string sqlCmd)

    {

    sqlCommand = new SqlCommand(sqlCmd, sqlConnection);

    SqlDataAdapter adapter = new SqlDataAdapter();

    adapter.SelectCommand = sqlCommand;

    DataTable table = new DataTable();

    table.Locale = System.Globalization.CultureInfo.InvariantCulture;

    adapter.Fill(table); // I want to allow users to cancel this statement which is run by BackgroundWorker

    sqlCommand = null;

    return table;

    }

    P.S How can I format code examples for the forum

    Thanks again.


  • Backgroundworker + Sql