Intermittent Problem Filling DataSet (Access 12)

J

Jeff Gaines

I have an intermittent problem filling a DataSet, it will happily work as
expected then raise an exception:

System.Data.OleDb.OleDbException was unhandled
Message="Unspecified error"
Source="Microsoft Office Access Database Engine"
ErrorCode=-2147467259

The code is:

//Returns all records in a List
internal static List<JCurrentAdvertsData> AllRecords()
{
List<JCurrentAdvertsData> listRecords = new List<JCurrentAdvertsData>();
JCurrentAdvertsData currentAdvertsData;
//Create the SelectCommand.
string selectString = "SELECT * FROM " + m_TableName;
selectString += " ORDER BY AdHeading";
//Create Connection
m_OleDbConnection = GetOleDbConnection();
m_OleDbDataAdapter = CreateSelectAdapter(m_OleDbConnection, selectString);
//Create / Fill the dataset
m_DataSet = new DataSet();

EXCEPTION arises here:
m_OleDbDataAdapter.Fill(m_DataSet, m_TableName);

//Get the Table from the Dataset
m_DataTable = m_DataSet.Tables[0];

// Loop through the Dataset and add each Row to the List
foreach (DataRow dataRow in m_DataTable.Rows)
{
currentAdvertsData = new JCurrentAdvertsData();
GetRecordDetails(dataRow, ref currentAdvertsData);
listRecords.Add(currentAdvertsData);
}
return listRecords;
}

The functions it calls are:

//GetOleDbConnection
private static OleDbConnection GetOleDbConnection()
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=";
connectionString += m_DBPath;
OleDbConnection oleConnection = null;
try
{
oleConnection = new OleDbConnection(connectionString);
}
catch
{
}
return oleConnection;
}

private static OleDbDataAdapter CreateSelectAdapter(OleDbConnection
connection, string selectString)
{
OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
OleDbCommand commandSelect = new OleDbCommand(selectString, connection);
oledbAdapter.SelectCommand = commandSelect;
return oledbAdapter;
}

The vaiables starting m_ are static, as is the class.

Is there any way of getting some detail of this "Unspecified error"? I am
beginning to wonder if the PC is too fast for Access and it needs some
time to recover between calls, or perhaps I should be closing/disposing of
something between calls.

Any ideas would be very much appreciated!
 
J

Jeff Gaines

On 16/10/2008 in message <[email protected]> Jeff
Gaines wrote:

[snipped]

Additional information.
Having set up various try/catch blocks so the app keeps running I have
discovered that once an exception has been raised in accessing 1 of the
tables then it continues to be raised when accessing any of the other
tables as well.
 
J

Jeff Gaines

On 16/10/2008 in message <[email protected]> Jeff
Gaines wrote:

[snipped]

Additional information.
Having set up various try/catch blocks so the app keeps running I have
discovered that once an exception has been raised in accessing 1 of the
tables then it continues to be raised when accessing any of the other
tables as well.

Sorry to keep replying to myself!

It looks like this was a type of speed issue. It was possible to click a
button to refresh a ListView before a previous refresh was complete so the
code was re-entering itself while previous connections were still
open/running. I now disable the refresh button and re-enable it once the
LV is filled and no problems since then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top