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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Context issues using application fields in classes

Status
Not open for further replies.

xavstone

Technical User
Apr 12, 2005
33
GB
Hi,

Im getting the error "The name 'Application' does not exist in the current context" with the piece of code below. Which is strange becuase i thought application fields were global. Im getting the errors with the server.transfer methods as well.

Im thinking it may have something to do with server paths. The content of the class worked fine in the aspx code behind.

Im a newbie so sorry if this is a 'groaner'.

public class Art_DBQueries
{
public Art_DBQueries()
{
//
// TODO: Add constructor logic here
// Add dtababase connection strings here
}

public void addArticle(string tit, string aut, string des, string con, string dat)
{

SqlDataSource AddArt = new SqlDataSource();

AddArt.ConnectionString = ConfigurationManager.ConnectionStrings[Application["ConnectDB"].ToString()].ToString();

AddArt.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
AddArt.InsertCommand = "AddArticle";

AddArt.InsertParameters.Add("heading", tit);
AddArt.InsertParameters.Add("author", aut);
AddArt.InsertParameters.Add("description", des);
AddArt.InsertParameters.Add("artcontent", con);
AddArt.InsertParameters.Add("datewritten", dat);

int rowsaffected = 0;

try
{
rowsaffected = AddArt.Insert();
}
catch (Exception ex)
{
Server.Transfer("StandardError.aspx");
}
finally
{
AddArt = null;
Server.Transfer("article_abc.aspx");
}


}
}
 
HttpApplication ha = (HttpApplication)HttpContext.Current.ApplicationInstance;

string strConn = ha.Application["ConnectDB"].ToString();

I've not tested this at all but it may help?
 
Thanks, julesey, that seems to be a winner.

Anyideas on the server.transfers?
 
thank you very much everything is working just fine now :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top