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!
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!