我创建了一个静态实用程序类来简化对数据库的访问,当我运行代码“TypeInitializationException”时出现以下异常。
<connectionStrings>
<add name="vistConnectionString" connectionString="XXXXX"/>
</connectionStrings>
static class DBUtility
{
private static string dbConnection = ConfigurationManager.ConnectionStrings["vistConnectionString"].ConnectionString;
public static string DbConnection
{
get { return dbConnection; }
}
}
如果我调用静态属性,那么我会收到一个 TypeInitializationException 异常
string s = DBUtility.DbConnection; // this line throws the exception
来自异常的消息是
Message=The type initializer for 'VIServiceToolServiceLibrary.Database.DBUtility' threw an exception.