merlyn2450
Programmer
I'm having unusual results with the following block of code. I'm having issues with the Application state "losing" its data. If the Application was emptying I wouldnt have any trouble, but the DataTable being stored loses all of its rows and keeps the schema intact. If it were empty and I requested it from the GetProductCategoriesFromApplication() method, it would be refilled, but its not. I'm trying to bind that data to a page control, so it tends to cause errors.
On my test server I run state InProc. I had suspected that the problem was related to the StateServer being used by the host, but I've been having problems on the test machine, too.
The code
//////////////////////////////
const string Application_PRODUCTCATEGORY = "GetProductCategories";
public static DataTable GetProductCategoriesFromApplication ()
{
if ( HttpContext.Current.Application [ Application_PRODUCTCATEGORY ] == null )
{
HttpContext.Current.Application [ Application_PRODUCTCATEGORY ] = GetProductCategories ();
}
return (DataTable) HttpContext.Current.Application [ Application_PRODUCTCATEGORY ];
}
public static DataTable GetProductCategories ()
{
IDbConnection objConn = ApplicationMgr.GetDbBuilder().getConnection();
if ( objConn is SqlConnection )
{
try
{
SqlCommand objWorkCommand = new SqlCommand ( "sp_SPL_GetProductCategory", (SqlConnection) objConn );
DataTable objWorkTable = DataSetBuilder.SQLProcedure ( objWorkCommand );
objConn.Close();
return objWorkTable;
}
catch ( System.Exception e )
{
HttpContext.Current.Trace.Write ( "GetProductCategoriesWithSql", e.Message );
return GetProductCategoriesWithOle ( objConn );
}
}
else
{
return GetProductCategoriesWithOle ( objConn );
}
}
private static DataTable GetProductCategoriesWithOle ( IDbConnection objConn )
{
StringBuilder objStrBuilder = new StringBuilder();
objStrBuilder.Append ( "SELECT * FROM tblProductCategory ORDER BY categoryTitle ASC" );
try
{
DataTable objWorkTable = DataSetBuilder.SQLQuery ( objStrBuilder.ToString(), objConn );
objConn.Close();
return objWorkTable;
}
catch ( System.Exception e )
{
HttpContext.Current.Trace.Write ( "GetProductCategoryByIDWithOle", e.Message );
objConn.Close();
return new DataTable();
}
}
//////////////////////////////
On my test server I run state InProc. I had suspected that the problem was related to the StateServer being used by the host, but I've been having problems on the test machine, too.
The code
//////////////////////////////
const string Application_PRODUCTCATEGORY = "GetProductCategories";
public static DataTable GetProductCategoriesFromApplication ()
{
if ( HttpContext.Current.Application [ Application_PRODUCTCATEGORY ] == null )
{
HttpContext.Current.Application [ Application_PRODUCTCATEGORY ] = GetProductCategories ();
}
return (DataTable) HttpContext.Current.Application [ Application_PRODUCTCATEGORY ];
}
public static DataTable GetProductCategories ()
{
IDbConnection objConn = ApplicationMgr.GetDbBuilder().getConnection();
if ( objConn is SqlConnection )
{
try
{
SqlCommand objWorkCommand = new SqlCommand ( "sp_SPL_GetProductCategory", (SqlConnection) objConn );
DataTable objWorkTable = DataSetBuilder.SQLProcedure ( objWorkCommand );
objConn.Close();
return objWorkTable;
}
catch ( System.Exception e )
{
HttpContext.Current.Trace.Write ( "GetProductCategoriesWithSql", e.Message );
return GetProductCategoriesWithOle ( objConn );
}
}
else
{
return GetProductCategoriesWithOle ( objConn );
}
}
private static DataTable GetProductCategoriesWithOle ( IDbConnection objConn )
{
StringBuilder objStrBuilder = new StringBuilder();
objStrBuilder.Append ( "SELECT * FROM tblProductCategory ORDER BY categoryTitle ASC" );
try
{
DataTable objWorkTable = DataSetBuilder.SQLQuery ( objStrBuilder.ToString(), objConn );
objConn.Close();
return objWorkTable;
}
catch ( System.Exception e )
{
HttpContext.Current.Trace.Write ( "GetProductCategoryByIDWithOle", e.Message );
objConn.Close();
return new DataTable();
}
}
//////////////////////////////