6 Replies - 68729 Views - Last Post: 18 January 2009 - 10:55 AM Rate Topic: -----

#1 sawman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-February 07

CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 01:38 PM

I'm scratching my head on this one. The code shown here generates this Compilation error:

Compiler Error Message: CS0103: The name 'context' does not exist in the current context

Source Error:

Line 24: public AppEnv(HttpContext Context)
Line 25: {
Line 26: context = Context;
Line 27: } //--------------------------------------------------------------- End public AppEnv().
Line 28:

using System;
using System.Collections.Specialized;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for AppEnv
/// </summary>
/// 

namespace Genealogy
{

	public class AppEnv
	{

		public AppEnv(HttpContext Context)
		{
		context = Context;
		} //--------------------------------------------------------------- End public AppEnv().

		public string GetAppSetting(string setting)
		{
			string val;
			try
			{
				val = (string)((NameValueCollection)context.GetConfig("appSettings"))[setting];
			} // End try.
			catch (NullReferenceException)
			{
				val = "";
			} // End catch.

			if (val == null)
			{
				val = "";
			} // End if.
			return val;
		} //------------------------------------------------- End public string GetAppSetting().

		public SqlConnection GetConnection()
		{
			SqlConnection myConnection = new SqlConnection();

			myConnection.ConnectionString = "server" + GetAppSetting("datasource") +
				";database=" + GetAppSetting("database") +
				";uid=" + GetAppSetting("userid") +
				";pwd=" + GetAppSetting("password") +
				((GetAppSetting("timeout").Length > 0) ? ";Connection Timeout=" + GetAppSetting("timeout")
				: "");

			return myConnection;
		} //------------------------------------------ End public SqlConnection GetConnection().

	} //------------------------------------------------------------- End public class AppEnv{}.
} //----------------------------------------------------------------- End namespace Genealogy{}.



Any idea's?

This post has been edited by sawman: 17 January 2009 - 01:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: CS0103: The name 'context' does not exist in the current conte

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 02:24 PM

you never declare a lower-case "context". You are passing in the uppercase "Context", but you don't have a lower-case.
Was This Post Helpful? 0
  • +
  • -

#3 sawman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-February 07

Re: CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 03:12 PM

View Posteclipsed4utoo, on 17 Jan, 2009 - 01:24 PM, said:

you never declare a lower-case "context". You are passing in the uppercase "Context", but you don't have a lower-case.


Thanks for the reply. I'm not sure I follow your meaning. I am using the lowercase context in the GetAppSetting function.

Are you trying to say that I never declared a lowercase context anywhere else, or that I am never supposed to declare a lowercase context?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 04:51 PM

He is saying you did not declare an object called 'context'. And if you did, show us where you have declared it.
Was This Post Helpful? 0
  • +
  • -

#5 sawman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-February 07

Re: CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 07:31 PM

View PostJayman, on 17 Jan, 2009 - 03:51 PM, said:

He is saying you did not declare an object called 'context'. And if you did, show us where you have declared it.


Okay, that makes better sense. I thought that all I needed to do was make context equal to the inherited Context member variable used as a parameter in the constructor. This is in fact all that happens in the constructor. So, where and how should I declare it as an object?

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: CS0103: The name 'context' does not exist in the current conte

Posted 17 January 2009 - 09:25 PM

Because you are using it in more than one method you need to declare it at the class level.

	public class AppEnv
	{
		private HttpContext context;

		public AppEnv(HttpContext Context)
		{
		context = Context;
		} //--------------------------------------------------------------- End public AppEnv().


Was This Post Helpful? 0
  • +
  • -

#7 sawman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-February 07

Re: CS0103: The name 'context' does not exist in the current conte

Posted 18 January 2009 - 10:55 AM

View PostJayman, on 17 Jan, 2009 - 08:25 PM, said:

Because you are using it in more than one method you need to declare it at the class level.

	public class AppEnv
	{
		private HttpContext context;

		public AppEnv(HttpContext Context)
		{
		context = Context;
		} //--------------------------------------------------------------- End public AppEnv().



Thanks Jayman, that did the trick!!! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1