Russ

Russ

  • NA
  • 3
  • 0

Cannot evaluate expression because a native frame is on top of the call stack on Forms app using odbc

Feb 23 2009 7:42 AM

Hi Folks,

First post here - I am aLAMP developer moving over to C# and I think it is great BUT I am just debugging the 1st parts of a new project in c# and keep hitting this problem:  I have a simple form which when an update button is clicked an odbc class is fired which connectects to a CAD database file via a third party odbc driver and extracts info about the elements in the CAD model - simple database query which works and returns the data, it just poulates a number of rectangular arrays so the connection works and retrieves the correct data.  This fully completes and the I run through to close the connections and clean up - it is then I get the above error and also a box pops up with the following message:

Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Seems to me like the connection is locked by something else but I cannot track it down!!

*** This is the code where the query is called from:

private void buttonUpdateFromPlan_Click(object sender, EventArgs e)

{

odbcConnect locConnToPlan = new odbcConnect();

locConnToPlan.connectToPlanFile("D:\\Graphisoft API\\Projects\\model1.pln", "D:\\Graphisoft API\\Projects\\model1.pln");

locConnToPlan.getWallDataFromPlan();

}

--------------------------------------------------------------------------------------------------------------------------------

*** This is the code from the seperate class for the odbc connection:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Odbc;

using System.Windows.Forms;

namespace ArchiInfo

{

public class odbcConnect

{

public string connectionString = "";

public OdbcConnection loadPlan;

private OdbcDataReader sqlReader;

private OdbcCommand sqlCommand;

private string errString = "";

public Char[,] wall_ID = new Char[100,1];

public Char[,] wall_USERID = new Char[100, 1];

public Double[,] wall_LENGTH_SIDE_A = new Double[100, 1];

public Double[,] wall_LENGTH_SIDE_B = new Double[100, 1];

public Double[,] wall_SURFACE_SIDE_A = new Double[100, 1];

public Double[,] wall_SURFACE_SIDE_B = new Double[100, 1];

public Double[,] wall_SURFACE_SIDE_C = new Double[100, 1];

public Double[,] wall_CENTER_LENGTH = new Double[100, 1];

 

public void connectToPlanFile(string planDirStr, string libDirString)

{

string connString = "DRIVER={ArchiCAD 11 Project ODBC Driver}; PLANFILE=" + planDirStr + "; LIBRARIES=" + libDirString + "";

 

loadPlan = new OdbcConnection(connString);

try

{

loadPlan.Open();

}

catch(OdbcException ex)

{

errString = "Exception Handled: " + ex.Message;

MessageBox.Show(errString);

return;

}

}

 

public void getWallDataFromPlan()

{

string sqlQuery = "SELECT id, userid, length_on_sidea, length_on_sideb, surface_on_sidea, surface_on_sideb, surface_on_sidec, center_length FROM walls";

sqlCommand = new OdbcCommand(sqlQuery, loadPlan);

sqlCommand.CommandText = sqlQuery;

try

{

sqlReader = sqlCommand.ExecuteReader();

}

catch (OdbcException ex)

{

errString = "Exception Handled: " + ex.Message;

MessageBox.Show(errString);

return;

}

try

{

int rowCounter = 0;

while (sqlReader.Read())

{

wall_ID[rowCounter, 0] = sqlReader.GetChar(0);

wall_USERID[rowCounter, 0] = sqlReader.GetChar(1);

wall_LENGTH_SIDE_A[rowCounter, 0] = sqlReader.GetDouble(2);

wall_LENGTH_SIDE_B[rowCounter, 0] = sqlReader.GetDouble(3);

wall_SURFACE_SIDE_A[rowCounter, 0] = sqlReader.GetDouble(4);

wall_SURFACE_SIDE_B[rowCounter, 0] = sqlReader.GetDouble(5);

wall_SURFACE_SIDE_C[rowCounter, 0] = sqlReader.GetDouble(6);

wall_CENTER_LENGTH[rowCounter, 0] = sqlReader.GetDouble(7);

rowCounter++;

}

}

catch (OdbcException ex)

{

errString = "Exception Handled: " + ex.Message;

MessageBox.Show(errString);

return;

}

finally

{

sqlReader.Close();

sqlReader.Dispose();

sqlCommand.Dispose();

loadPlan.Close();

loadPlan.Dispose();

}

}

}

}

--------------------------------------------------------------------------------------------------------

The errors occur when the code gets throug to loadPlan.Close();

Any help to get this resolved would be much apreciated as I seem to be going around in circles.

Thanks


Answers (2)