Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does my .NET 2.0 application crash under .NET 4.0 when I use a OleDbDataAdapter object without an OleDBConnection object?

This is a .NET 2.0 application written using VS 2005. It works fine on systems running .NET 2.0, but hard crashes on systems running .NET 4.0. Here's the critical section of the code:

      string selectCommand1 = ....
      string connectionString1 = ....
      using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand1, connectionString1))
        {
            try
            {
                adapter.Fill(table1);
            }
            catch
            {
               MessageBox.Show("error");
            }
        }

      string selectCommand2 = ....
      string connectionString2 = ....
      using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand2, connectionString2))
        {
            try
            {
                adapter.Fill(table2);
            }
            catch
            {
               MessageBox.Show("error");
            }
        }

Again, it works under .NET 2.0, crashes under .NET 4.0

ConnectionStrings 1 & 2 reference different .xls files.

I found that the way around this problem is to declare and initialize a field variable of type OleDbConnection, set the ConnectionString property and Open() it before the OleDbDataAdapter's using statement. As so:

 OleDbConnection connection = new OleDbConnection();

  .......

        connection.ConnectionString = connectionString1;
        connection.Open();
        using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand1, connection))
        {
            try
            {
                adapter.Fill(table1);
            }
            catch
            {
                MessageBox.Show("error");
            }
        }

        connection.Close();
        connection.ConnectionString = connectionString2;
        connection.Open();
        using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand2, connection))
        {
            try
            {
                adapter.Fill(table2);
            }
            catch
            {
                MessageBox.Show("error");
            }
        }

It's hard to believe that this is the reason why my app was hard crashing (no error messages) under .NET 4.0, but after removing lines of code one at a time and recompiling over and over I found that to be the cause of the problem.

I'm glad I solved the problem, but I'm not satisfied with the fact that the first code won't work with .NET 4.0.

Can someone please explain why .NET 4.0 doesn't like to work with code like the one above?

like image 856
John Smith Avatar asked Jul 11 '12 18:07

John Smith


1 Answers

The problem was "Application Verifier". Uninstalling it solved the problem.

like image 58
John Smith Avatar answered Oct 11 '22 17:10

John Smith