J
jensen bredal
I need a thread that loads the content of a database table in the cache
(System.Web.Caching.Cache)
i wrote therefore the code below:
public class Global : System.Web.HttpApplication
{
.....
......
......
public static Thread t;
{
get { return post; }
}
public Global()
{
InitializeComponent();
}
public static String GetConnectionString
{
get { return ConfigurationSettings.AppSettings["DBConnStr"]; }
}
protected void Application_Start(Object sender, EventArgs e)
{
DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionString,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.FromHours(2));
t = new Thread(new ThreadStart(ThreadProc));
t.Start();
Thread.Sleep(3600);
}
.....
......
.......
public void ThreadProc()
{
try
{
DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionString,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.FromHours(2));
}
catch(Exception ex)
{
string str = ex.Message; // get the exeption as a string
}
....
......
.....
But!!!
This cause the exception: "object reference not set to an instance of
anobject"
Can someone tell me what i'm doing wrong?
Many thanks in advance
JB
(System.Web.Caching.Cache)
i wrote therefore the code below:
public class Global : System.Web.HttpApplication
{
.....
......
......
public static Thread t;
{
get { return post; }
}
public Global()
{
InitializeComponent();
}
public static String GetConnectionString
{
get { return ConfigurationSettings.AppSettings["DBConnStr"]; }
}
protected void Application_Start(Object sender, EventArgs e)
{
DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionString,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.FromHours(2));
t = new Thread(new ThreadStart(ThreadProc));
t.Start();
Thread.Sleep(3600);
}
.....
......
.......
public void ThreadProc()
{
try
{
DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionString,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.FromHours(2));
}
catch(Exception ex)
{
string str = ex.Message; // get the exeption as a string
}
....
......
.....
But!!!
This cause the exception: "object reference not set to an instance of
anobject"
Can someone tell me what i'm doing wrong?
Many thanks in advance
JB