0
我已經存儲了我的連接字符串中myGlobals.cs
頁面如下:全球的ConnectionString未初始化
/* Connection String */
public static string conString
{
get { return _conString; }
set { _conString = ConfigurationManager.ConnectionStrings["BaseConnectionString"].ToString(); }
}
我在4層架構我的代碼設置。所以我有一個業務對象文件夾,業務訪問層&數據訪問層。如果我將連接字符串移動到DAL結構中,它可以正常工作。其他明智的,我得到這個錯誤:
The ConnectionString property has not been initialized
不被包含在此之前的所有myGlobals.cs類或是否需要被周圍改變?
這裏是我的數據訪問層:
public DataTable Load()
{
SqlConnection conn = new SqlConnection(MyGlobals.conString);
SqlDataAdapter dAd = new SqlDataAdapter("administratorGetAll", conn);
dAd.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet dSet = new DataSet();
try
{
dAd.Fill(dSet, "AdministratorsTable");
return dSet.Tables["AdministratorsTable"];
}
catch
{
throw;
}
finally
{
dSet.Dispose();
dAd.Dispose();
conn.Close();
conn.Dispose();
}
}
你只設置時,它是連接字符串..:
MyClass.MyProperty = "new value";
你想要做的這一點 - 當你把財產在賦值的左側執行其代碼設置。所以它從來沒有初始化,除非你設置它(在這種情況下,你忽略它設置的值......) – Cameron 2011-03-22 02:50:59