The type initializer for 'DataAccess.DAL' threw an exception

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Ok. I have a C# Winform and am using common practices of a three layered application. A User Interface, a Business Access Layer, and a Data Access Layer. The user interface seems to be communicating just fine with the Business Access Layer, but something
crashes between the Business Access Layer and the Data Access Layer. I have a good number of things being passed through, but I will give you my initial error that is happening (I can only assume everything else will do the same thing, as the application flags
an error before these functions are called). On some of the other things there is also a reference to a Common.Entities Class, other than that all things are referenced correctly and I assume my app.config file is set up correctly because these functions work
when I bumb them up a level to the Business Access Layer.
User Interface:
<div style="background-color:white; color:black
<pre><span style="color:blue private <span style="color:blue void tmrCheck_Elapsed(<span style="color:blue object sender, System.Timers.ElapsedEventArgs e)
{
tmrCheck.Enabled = <span style="color:blue false;

<span style="color:blue if (BAL.CheckSQLConnection() == <span style="color:blue true)
{
<span style="color:blue if (BAL.CheckAccessConnection() == <span style="color:blue true)
{
BAL.InsertNewRecords();
}
<span style="color:blue else
{
log = <span style="color:blue new WriteToLog(<span style="color:#a31515 "Error Connecting To Access Database");
}
}
<span style="color:blue else
{
log = <span style="color:blue new WriteToLog(<span style="color:#a31515 "Error Connecting To SQL Database");
}
}
[/code]

Business Access Layer:
<div style="background-color:white; color:black
<pre><span style="color:blue public <span style="color:blue static Boolean CheckAccessConnection()
{
Boolean results = DAL.CheckAccessConnection();

<span style="color:blue return results;
}


[/code]

Data Access Layer:
<pre><pre lang="x-c# public static Boolean CheckAccessConnection()
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = ConfigurationManager.AppSettings.Get("LocalDBConnectionString");
try
{
conn.Open();
return true;
}
catch
{
return false;
}
finally
{
conn.Dispose();
}
}[/code]
<br/><br/>What I did was bump the functions up a level and tested them out one by one and with the CheckAccessConnection() at the Data Access Layer I got the following flag:<br/><br/>"The type initializer for DataAccess.DAL threw an exception"[/code]
The Inner Exception was the following flag:<br/>
<br/>
"{"The requested database Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Partner\results\results3.mdb; is not defined in configuration."}"
Like I said, all of this works when I bump it up to either the BAL or the UI, but this error comes up when I am at the DAL. Any thoughts? This code is pretty rudimentary and I dont understand where the error is coming from.
<br/>

View the full article
 
Back
Top