Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ApplicationState error

Status
Not open for further replies.

merlyn2450

Programmer
Dec 26, 2002
17
US
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();
}
}

//////////////////////////////
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top