473,903 Members | 3,317 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable Goes Out Of Scope When Used In Remoted Class

On the host server:

namespace JCart.Common
public class JCartConfigurat ion : IConfigurationS ectionHandler
private static String dbConnectionStr ing;
public static String ConnectionStrin g
{
get
{
return dbConnectionStr ing;
}
}
//Initialze it:
dbConnectionStr ing = "My Database Connection String";
On remote server:

namespace JCart.DataAcces s
public class CustomerSystem : MarshalByRefObj ect
String testVar;
testVar = JCartConfigurat ion.ConnectionS tring;

testVar comes back as "". However when this exact code is used without being remoted testVar = "My Database Connection String";

This is basically the Duwamish .Net sample cloned minus the shopping cart that I useed as a way to learn c#. No enterprise template but the same seperate projects structure within the solution only containg the stuff needed to implement the account setup/modify system part.

I'm not sure if I'm overlooking some basic concept, but I can post more details if necessary.

Here is the remote config file when used:

<configuratio n>
<system.runtime .remoting>
<application>
<channels>
<channel ref="http client" clientConnectio nLimit="200">
<clientProvider s>
<formatter ref="soap"/>
</clientProviders >
</channel>
</channels>
<client url="HTTP://192.168.1.13:80/JCart_Facade">
<wellknown type="JCart.Bus inessFacade.Cus tomerSystem, JCart.BusinessF acade" url="HTTP://192.168.1.13:80/JCart_Facade/CustomerSystem. rem"/>
</client>
</application>
</system.runtime. remoting>
</configuration>



Nov 15 '05 #1
10 3495
Just switched from Verizon DSL to RR and forgot to put my email address, it's cs****@nyc.rr.c om
"Not Available" <no**********@b .com> wrote in message news:1O******** *************@t wister.nyc.rr.c om...
On the host server:

namespace JCart.Common
public class JCartConfigurat ion : IConfigurationS ectionHandler
private static String dbConnectionStr ing;
public static String ConnectionStrin g
{
get
{
return dbConnectionStr ing;
}
}
//Initialze it:
dbConnectionStr ing = "My Database Connection String";
On remote server:

namespace JCart.DataAcces s
public class CustomerSystem : MarshalByRefObj ect
String testVar;
testVar = JCartConfigurat ion.ConnectionS tring;

testVar comes back as "". However when this exact code is used without being remoted testVar = "My Database Connection String";

This is basically the Duwamish .Net sample cloned minus the shopping cart that I useed as a way to learn c#. No enterprise template but the same seperate projects structure within the solution only containg the stuff needed to implement the account setup/modify system part.

I'm not sure if I'm overlooking some basic concept, but I can post more details if necessary.

Here is the remote config file when used:

<configuratio n>
<system.runtime .remoting>
<application>
<channels>
<channel ref="http client" clientConnectio nLimit="200">
<clientProvider s>
<formatter ref="soap"/>
</clientProviders >
</channel>
</channels>
<client url="HTTP://192.168.1.13:80/JCart_Facade">
<wellknown type="JCart.Bus inessFacade.Cus tomerSystem, JCart.BusinessF acade" url="HTTP://192.168.1.13:80/JCart_Facade/CustomerSystem. rem"/>
</client>
</application>
</system.runtime. remoting>
</configuration>



Nov 15 '05 #2
Not Available <no**********@b .com> wrote:
On the host server:

namespace JCart.Common
public class JCartConfigurat ion : IConfigurationS ectionHandler
private static String dbConnectionStr ing;
public static String ConnectionStrin g
{
get
{
return dbConnectionStr ing;
}
}
//Initialze it:
dbConnectionStr ing = "My Database Connection String";


Where is that connection string being initialised though? You haven't
shown that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
The connection string is initialized from a web.config file. I've included the complete modules JCartConfigurat ion, ApplicationConf iguration and the Web.config files below. Here are the lines:

JCartConfigurat ion:
dbConnectionStr ing = ApplicationConf iguration.ReadS etting(settings , DATAACCESS_CONN ECTIONSTRING, DATAACCESS_CONN ECTIONSTRING_DE FAULT);

ApplicationConf iguration:
System.Configur ation.Configura tionSettings.Ge tConfig("JCartC onfiguration");

Web.config:

<JCartConfigura tion>
<!-- Settings specific to the Duwamish application -->
<add key="JCart.Data Access.Connecti onString" value="server=E MPIRE2;User ID=sa;Password= ;database=JCart ;Connection Reset=FALSE" />
Here's the global.asx.cs file
protected void Application_Sta rt(Object sender, EventArgs e)
{
ApplicationConf iguration.OnApp licationStart(C ontext.Server.M apPath( Context.Request .ApplicationPat h ));
AppStartDateTim e = dt.ToString();
string configPath = Path.Combine(Co ntext.Server.Ma pPath( Context.Request .ApplicationPat h ),"remotingclie nt.cfg");
if(File.Exists( configPath))
RemotingConfigu ration.Configur e(configPath);
}




"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com...
Not Available <no**********@b .com> wrote:
On the host server:

namespace JCart.Common
public class JCartConfigurat ion : IConfigurationS ectionHandler
private static String dbConnectionStr ing;
public static String ConnectionStrin g
{
get
{
return dbConnectionStr ing;
}
}
//Initialze it:
dbConnectionStr ing = "My Database Connection String";


Where is that connection string being initialised though? You haven't
shown that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

JCARTCONFIGURAT ION.cs
namespace JCart.Common
{
using System;
using System.Collecti ons;
using System.Configur ation;
using System.Xml;
using System.Collecti ons.Specialized ;
using JCart.SystemFra mework;


public class JCartConfigurat ion : IConfigurationS ectionHandler

// public class JCartConfigurat ion
{
//
// Constant values for all expected entries in the DuwamishConfigu ration section
//
private const String WEB_ENABLEPAGEC ACHE = "JCart.Web.Enab lePageCache";
private const String WEB_PAGECACHEEX PIRESINSECONDS = "JCart.Web.Page CacheExpiresInS econds";
private const String DATAACCESS_CONN ECTIONSTRING = "JCart.DataAcce ss.ConnectionSt ring";
private const String WEB_ENABLESSL = "JCart.Web.Enab leSsl";

private static String dbConnectionStr ing;
// public static int test1p;

// private static bool enablePageCache ;
// private static int pageCacheExpire sInSeconds;
// private static bool enableSsl;
//
// Constant values for all of the default settings.
//
private const bool WEB_ENABLEPAGEC ACHE_DEFAULT = true;
private const int WEB_PAGECACHEEX PIRESINSECONDS_ DEFAULT = 3600;
private const String DATAACCESS_CONN ECTIONSTRING_DE FAULT =
"server=EMPIRE2 ;User ID=sa;Password= ;database=JCart ;Connection Reset=FALSE";
private const bool WEB_ENABLESSL_D EFAULT = false;


public Object Create(Object parent, object configContext, XmlNode section)
{

NameValueCollec tion settings;

try
{
NameValueSectio nHandler baseHandler = new NameValueSectio nHandler();
settings = (NameValueColle ction)baseHandl er.Create(paren t, configContext, section);
}
catch
{
settings = null;
}

if ( settings == null )
{
dbConnectionStr ing = DATAACCESS_CONN ECTIONSTRING_DE FAULT;
// pageCacheExpire sInSeconds = WEB_PAGECACHEEX PIRESINSECONDS_ DEFAULT;
// enablePageCache = WEB_ENABLEPAGEC ACHE_DEFAULT;
// enableSsl = WEB_ENABLESSL_D EFAULT;
}
else
{
dbConnectionStr ing = ApplicationConf iguration.ReadS etting(settings , DATAACCESS_CONN ECTIONSTRING, DATAACCESS_CONN ECTIONSTRING_DE FAULT);
// pageCacheExpire sInSeconds = ApplicationConf iguration.ReadS etting(settings , WEB_PAGECACHEEX PIRESINSECONDS, WEB_PAGECACHEEX PIRESINSECONDS_ DEFAULT);
// enablePageCache = ApplicationConf iguration.ReadS etting(settings , WEB_ENABLEPAGEC ACHE, WEB_ENABLEPAGEC ACHE_DEFAULT);
// enableSsl = ApplicationConf iguration.ReadS etting(settings , WEB_ENABLESSL, WEB_ENABLESSL_D EFAULT);
}

return settings;
}

public static String ConnectionStrin g
{
get
{
return dbConnectionStr ing;
}
}

// public static int test1
// {
// get
// {
// return test1p;
// }
// }

} //class JCartConfigurat ion
} //namespace JCart7.Common
APPLICATIONCONF IGURATION.CS

namespace JCart.SystemFra mework
{
using System;
using System.Collecti ons;
using System.Diagnost ics;
using System.Configur ation;
using System.Xml;
using System.Collecti ons.Specialized ;


/// <summary>
/// Standard configuration settings to enable tracing and logging
/// with the ApplicationLog class.
/// <remarks>
/// An application can use this class as a model for
/// adding additional settings to a Web.Config file.
/// Special Considerations:
/// The OnApplicationSt art function in this class must be called
/// from the Application_OnS tart event in Global.asax. This is
/// currently used to determine the path of the application,
/// the HttpContext object is passed it to enable the app
/// to read other settings in the future, and to minimize the code
/// in global.asax.
/// <example>
/// The global.asax file should be similar to the following code:
/// <code>
/// <%@ Import Namespace="Duwa mish7.SystemFra mework" %>
/// <script language="c#" runat="SERVER">
/// void Application_OnS tart()
/// {
/// ApplicationConf iguration.OnApp licationStart(C ontext);
/// }
/// </script>
/// </code>
/// </example>
/// </remarks>
/// </summary>
public class ApplicationConf iguration : IConfigurationS ectionHandler
{

//
// Constant values for all of the SystemFramework standard settings
//
private const String TRACING_ENABLED = "SystemFramewor k.Tracing.Enabl ed";
private const String TRACING_TRACEFI LE = "SystemFramewor k.Tracing.Trace File";
private const String TRACING_TRACELE VEL = "SystemFramewor k.Tracing.Trace Level";
private const String TRACING_SWITCHN AME = "SystemFramewor k.Tracing.Switc hName";
private const String TRACING_SWITCHD ESCRIPTION = "SystemFramewor k.Tracing.Switc hDescription";
private const String EVENTLOG_ENABLE D = "SystemFramewor k.EventLog.Enab led";
private const String EVENTLOG_MACHIN ENAME = "SystemFramewor k.EventLog.Mach ine";
private const String EVENTLOG_SOURCE NAME = "SystemFramewor k.EventLog.Sour ceName";
private const String EVENTLOG_TRACEL EVEL = "SystemFramewor k.EventLog.LogL evel";

//
// Static member variables. These contain the application settings
// from Config.Web, or the default values.
//
private static bool tracingEnabled;
private static String tracingTraceFil e;
private static TraceLevel tracingTraceLev el;
private static String tracingSwitchNa me;
private static String tracingSwitchDe scription;
private static bool eventLogEnabled ;
private static String eventLogMachine Name;
private static String eventLogSourceN ame;
private static TraceLevel eventLogTraceLe vel;

//
// The root directory of the application. Established in the
// OnApplicationSt art callback form Global.asax.
//
private static String appRoot;

//
// Constant values for all of the default settings.
//
private const bool TRACING_ENABLED _DEFAULT = true;
private const String TRACING_TRACEFI LE_DEFAULT = "ApplicationTra ce.txt";
private const TraceLevel TRACING_TRACELE VEL_DEFAULT = TraceLevel.Verb ose;
private const String TRACING_SWITCHN AME_DEFAULT = "ApplicationTra ceSwitch";
private const String TRACING_SWITCHD ESCRIPTION_DEFA ULT = "Applicatio n error and tracing information";
private const bool EVENTLOG_ENABLE D_DEFAULT = true;
private const String EVENTLOG_MACHIN ENAME_DEFAULT = ".";
private const String EVENTLOG_SOURCE NAME_DEFAULT = "WebApplication ";
private const TraceLevel EVENTLOG_TRACEL EVEL_DEFAULT = TraceLevel.Erro r;

/// <summary>
/// Called from OnApplicationSt art to initialize settings from
/// the Web.Config file(s).
/// <remarks>
/// The app domain will restart if settings change, so there is
/// no reason to read these values more than once. This funtion
/// uses the NameValueSectio nHandler base class to generate a
/// hashtablefrom the XML, which is then used to store the current
/// settings. Because all settings are read here, we do not actually
/// store the generated hashtable object for later retrieval by
/// Context.GetConf ig. The application should use the accessor
/// functions directly.
/// </remarks>
/// <param name="parent">A n object created by processing a section
/// with this name in a Config.Web file in a parent directory.
/// </param>
/// <param name="configCon text">The config's context.</param>
/// <param name="section"> The section to be read.</param>
/// <retvalue>
/// <para>
/// A ConfigOutput object: which we leave empty because all settings
/// are stored at this point.
/// </para>
/// <para>
/// null: if there was an error.
/// </para>
/// </retvalue>
/// </summary>
public Object Create(Object parent, object configContext, XmlNode section)
{

NameValueCollec tion settings;

try
{
NameValueSectio nHandler baseHandler = new NameValueSectio nHandler();
settings = (NameValueColle ction)baseHandl er.Create(paren t, configContext, section);
}
catch
{
settings = null;
}

if (settings == null)
{
tracingEnabled = TRACING_ENABLED _DEFAULT;
tracingTraceFil e = TRACING_TRACEFI LE_DEFAULT;
tracingTraceLev el = TRACING_TRACELE VEL_DEFAULT;
tracingSwitchNa me = TRACING_SWITCHN AME_DEFAULT;
tracingSwitchDe scription = TRACING_SWITCHD ESCRIPTION_DEFA ULT;
eventLogEnabled = EVENTLOG_ENABLE D_DEFAULT;
eventLogMachine Name = EVENTLOG_MACHIN ENAME_DEFAULT;
eventLogSourceN ame = EVENTLOG_SOURCE NAME_DEFAULT;
eventLogTraceLe vel = EVENTLOG_TRACEL EVEL_DEFAULT;
}
else
{
tracingEnabled = ReadSetting(set tings, TRACING_ENABLED , TRACING_ENABLED _DEFAULT);
tracingTraceFil e = ReadSetting(set tings, TRACING_TRACEFI LE, TRACING_TRACEFI LE_DEFAULT);
tracingTraceLev el = ReadSetting(set tings, TRACING_TRACELE VEL, TRACING_TRACELE VEL_DEFAULT);
tracingSwitchNa me = ReadSetting(set tings, TRACING_SWITCHN AME, TRACING_SWITCHN AME_DEFAULT);
tracingSwitchDe scription = ReadSetting(set tings, TRACING_SWITCHD ESCRIPTION, TRACING_SWITCHD ESCRIPTION_DEFA ULT);
eventLogEnabled = ReadSetting(set tings, EVENTLOG_ENABLE D, EVENTLOG_ENABLE D_DEFAULT);
eventLogMachine Name = ReadSetting(set tings, EVENTLOG_MACHIN ENAME, EVENTLOG_MACHIN ENAME_DEFAULT);
eventLogSourceN ame = ReadSetting(set tings, EVENTLOG_SOURCE NAME, EVENTLOG_SOURCE NAME_DEFAULT);
eventLogTraceLe vel = ReadSetting(set tings, EVENTLOG_TRACEL EVEL, EVENTLOG_TRACEL EVEL_DEFAULT);
}

return null;
}

/// <summary>
/// String version of ReadSetting.
/// <remarks>
/// Reads a setting from a hashtable and converts it to the correct
/// type. One of these functions is provided for each type
/// expected in the hash table. These are public so that other
/// classes don't have to duplicate them to read settings from
/// a hash table.
/// </remarks>
/// <param name="settings" >The Hashtable to read from.</param>
/// <param name="key">A key for the value in the Hashtable.</param>
/// <param name="defaultVa lue">The default value if the item is not found.</param>
/// <retvalue>
/// <para>value: from the hash table</para>
/// <para>
/// default: if the item is not in the table or cannot be case to the expected type.
/// </para>
/// </retvalue>
/// </summary>
public static String ReadSetting(Nam eValueCollectio n settings, String key, String defaultValue)
{
try
{
Object setting = settings[key];

return (setting == null) ? defaultValue : (String)setting ;
}
catch
{
return defaultValue;
}
}

/// <summary>
/// Boolean version of ReadSetting.
/// <remarks>
/// Reads a setting from a hashtable and converts it to the correct
/// type. One of these functions is provided for each type
/// expected in the hash table. These are public so that other
/// classes don't have to duplicate them to read settings from
/// a hash table.
/// </remarks>
/// <param name="settings" >The Hashtable to read from.</param>
/// <param name="key">A key for the value in the Hashtable.</param>
/// <param name="defaultVa lue">The default value if the item is not found.</param>
/// <retvalue>
/// <para>value: from the hash table</para>
/// <para>
/// default: if the item is not in the table or cannot be case to the expected type.
/// </para>
/// </retvalue>
/// </summary>
public static bool ReadSetting(Nam eValueCollectio n settings, String key, bool defaultValue)
{
try
{
Object setting = settings[key];

return (setting == null) ? defaultValue : Convert.ToBoole an((String)sett ing);
}
catch
{
return defaultValue;
}
}

/// <summary>
/// int version of ReadSetting.
/// <remarks>
/// Reads a setting from a hashtable and converts it to the correct
/// type. One of these functions is provided for each type
/// expected in the hash table. These are public so that other
/// classes don't have to duplicate them to read settings from
/// a hash table.
/// </remarks>
/// <param name="settings" >The Hashtable to read from.</param>
/// <param name="key">A key for the value in the Hashtable.</param>
/// <param name="defaultVa lue">The default value if the item is not found.</param>
/// <retvalue>
/// <para>value: from the hash table</para>
/// <para>
/// default: if the item is not in the table or cannot be case to the expected type.
/// </para>
/// </retvalue>
/// </summary>
public static int ReadSetting(Nam eValueCollectio n settings, String key, int defaultValue)
{
try
{
Object setting = settings[key];

return (setting == null) ? defaultValue : Convert.ToInt32 ((String)settin g);
}
catch
{
return defaultValue;
}
}

/// <summary>
/// TraceLevel version of ReadSetting.
/// <remarks>
/// Reads a setting from a hashtable and converts it to the correct
/// type. One of these functions is provided for each type
/// expected in the hash table. These are public so that other
/// classes don't have to duplicate them to read settings from
/// a hash table.
/// </remarks>
/// <param name="settings" >The Hashtable to read from.</param>
/// <param name="key">A key for the value in the Hashtable.</param>
/// <param name="defaultVa lue">The default value if the item is not found.</param>
/// <retvalue>
/// <para>value: from the hash table</para>
/// <para>
/// default: if the item is not in the table or cannot be case to the expected type.
/// </para>
/// </retvalue>
/// </summary>
public static TraceLevel ReadSetting(Nam eValueCollectio n settings, String key, TraceLevel defaultValue)
{
try
{
Object setting = settings[key];

return (setting == null) ? defaultValue : (TraceLevel)Con vert.ToInt32((S tring)setting);
}
catch
{
return defaultValue;
}
}

/// <summary>
/// Function to be called by Application_OnS tart as described in the
/// class description. Initializes the application root.
/// <param name="myAppPath ">The path of the running application.</param>
/// </summary>
public static void OnApplicationSt art(String myAppPath)
{
appRoot = myAppPath;

// System.Configur ation.Configura tionSettings.Ge tConfig("Applic ationConfigurat ion");

System.Configur ation.Configura tionSettings.Ge tConfig("JCartC onfiguration");

// System.Configur ation.Configura tionSettings.Ge tConfig("Source Viewer");

}

/// <value>
/// Property AppRoot is used to get the root path of the application.
/// </value>
public static String AppRoot
{
get
{
return appRoot;
}
}

/// <value>
/// Property TracingEnabled is used to get the configuration setting, defaulting to False on error.
/// </value>
public static bool TracingEnabled
{
get
{
return tracingEnabled;
}
}

/// <value>
/// Property TracingTraceFil e is used to get the full path name to the file that contains trace
/// settings, defaults to ApplicationTrac e.txt.
/// </value>
public static String TracingTraceFil e
{
get
{
return appRoot + "\\" + tracingTraceFil e;
}
}

/// <value>
/// Property TracingTraceFil e is used to get the highest logging level that should be written to
/// the tracing file, defaults to TraceLevel.Verb ose (however, TracingEnabled defaults
/// to False, so you have to turn it on explicitly).
/// </value>
public static TraceLevel TracingTraceLev el
{
get
{
return tracingTraceLev el;
}
}

/// <value>
/// Property TracingSwitchNa me is used to get the trace switch name, defaults to ApplicationTrac eSwitch.
/// </value>
public static String TracingSwitchNa me
{
get
{
return tracingSwitchNa me;
}
}

/// <value>
/// Property TracingSwitchDe scription is used to get the trace settings file, defaults to
/// "Applicatio n error and tracing information".
/// </value>
public static String TracingSwitchDe scription
{
get
{
return tracingSwitchDe scription;
}
}

/// <value>
/// Property EventLogEnabled is used to get whether writing to the event log is support, defaults to True.
/// <remarks>Return s true if writing to the event log is enabled, false otherwise</remarks>
/// </value>
public static bool EventLogEnabled
{
get
{
return eventLogEnabled ;
}
}
/// <value>
/// Property EventLogMachine Name is used to get the machine name to log the event to, defaults to an
/// empty string, indicating the current machine. A machine name
/// (without \\), may be empty.
/// </value>
public static String EventLogMachine Name
{
get
{
return eventLogMachine Name;
}
}

/// <value>
/// Property EventLogMachine Name is used to get the source of the error to be written to the event log,
/// defaults WebApplication.
/// </value>
public static String EventLogSourceN ame
{
get
{
return eventLogSourceN ame;
}
}

/// <value>
/// Property EventLogTraceLe vel is used to get the highest logging level that should be written to the event log,
/// defaults to TraceLevel.Erro r.
/// </value>
public static TraceLevel EventLogTraceLe vel
{
get
{
return eventLogTraceLe vel;
}
}

} //class ApplicationConf iguration
} //namespace JCart.SystemFra mework
WEB.CONFIG

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="Applicati onConfiguration " type="JCart.Sys temFramework.Ap plicationConfig uration, JCart.SystemFra mework" />
<section name="JCartConf iguration" type="JCart.Com mon.JCartConfig uration, JCart.Common" />
</configSections>
<system.web>
<compilation defaultLanguage ="c#" debug="true" />
<!-- xx The sessionState is currently set to inproc: the lines following [mode="inproc"] are not used but are present for ease of configuration -->
<sessionState cookieless="fal se" timeout="20" mode="InProc" stateConnection String="tcpip=1 27.0.0.1:42424" sqlConnectionSt ring="data source=127.0.0. 1;user id=sa;password= " />
<globalizatio n requestEncoding ="utf-8" responseEncodin g="utf-8" />
<!-- security -->

<authenticati on mode="Windows" />
<!--
<authenticati on mode="Forms">
<forms name=".ADUAUTH2 " loginUrl="logon .aspx" protection="All " timeout="60" >
</forms>
</authentication>
<authorizatio n>
<deny users="?" />
</authorization>
-->

<trace enabled="false" requestLimit="1 0" pageOutput="fal se" traceMode="Sort ByTime" localOnly="true " />
</system.web>
<ApplicationCon figuration>
<!-- Trace file settings -->
<add key="SystemFram ework.Tracing.E nabled" value="False" />
<!-- Set this to the file with the trace settings. This file should be relative
to the root application directory. -->
<add key="SystemFram ework.Tracing.T raceFile" value="Duwamish Trace.txt" />
<!-- The TraceLevel for this switch. -->
<add key="SystemFram ework.Tracing.T raceLevel" value="4" />
<!-- This switch name. The trace level for this name can be set through
environment variables or the registry -->
<add key="SystemFram ework.Tracing.S witchName" value="Duwamish TraceSwitch" />
<!-- This description of the Tracing.SwitchN ame switch -->
<add key="SystemFram ework.Tracing.S witchDescriptio n" value="Error and information tracing for Duwamish" />
<!-- Event log settings
Note: The default Duwamish7 event source name is created in the local machine during setup. If you wish to log events to a different event source
that event source must exist.
-->
<add key="SystemFram ework.EventLog. Enabled" value="True" />
<add key="SystemFram ework.EventLog. Machine" value="." />
<add key="SystemFram ework.EventLog. SourceName" value="Duwamish 7" />
<!-- Use the standard TraceLevel values:
0 = Off
1 = Error
2 = Warning
3 = Info
4 = Verbose -->
<add key="SystemFram ework.EventLog. LogLevel" value="1" />
</ApplicationConf iguration>
<JCartConfigura tion>
<!-- Settings specific to the Duwamish application -->
<add key="JCart.Data Access.Connecti onString" value="server=E MPIRE2;User ID=sa;Password= ;database=JCart ;Connection Reset=FALSE" />
<add key="JCart.Web. EnablePageCache " value="True" />
<add key="JCart.Web. PageCacheExpire sInSeconds" value="3600" />
<add key="JCart.Web. EnableSsl" value="False" />
</JCartConfigurat ion>

<!-- String dsn = ConfigurationSe ttings.AppSetti ngs["JCart"];
<appSettings>
<add key="JCart" value="server=E MPIRE2;User ID=sa;Password= ;database=JCart ;Connection Reset=FALSE" />
</appSettings>
-->
</configuration>
Nov 15 '05 #4
Not Available <no**********@b .com> wrote:
The connection string is initialized from a web.config file.


I meant where is the connection string initialised, as in "in which
method". It looks like it's only initialised when the Create method is
called. Why not initialise it when the type is initialised instead?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
> I meant where is the connection string initialised, as in "in which
method". It looks like it's only initialised when the Create method is
I see your point. I don't think it is initialized anywhere else. I'm just guessing but somehow JCartConfigurat ion.ConnectionS tring when used non-remotley must pick up some left over private variable/instance but that doesn't happen when the object trying to use JCartConfigurat ion.ConnectionS tring is remote. I'm not sure if this "NameValueColle ction settings" object from the IConfigurationS ectionHandler is instantiated anywhere and thought it was part of the whole configuration handler functionality. The whole concept of the Duwamish remote business_facade :CustomerSystem MarshelByRef is to totally encapsulate everything and to make it completly stateless. That's why I thought the whole IConfiguration base class would somehow let you use the configuration stuff it reads from web.config in all remote objects. It seems to work that way in the remote setup of the Duwamish sample. Since I basically cloned the code without the project template and couldn't get the <section name="Applicati onConfiguration " part to work I thought it had something to do with that.

I guess I should make some time to do a pared down example of this. Basically I think the 'know how' I'm looking for is how to make configuration settings available to a stateless remote completly encasulated class. It looked like IConfigurationS ectionHandler woudl do that.
called. Why not initialise it when the type is initialised instead?
I might be misreading your question but I think the answer is because I want the remote class/dll/object to be totally encapsulated and stateless.

Here are some other thoughts:

I think there's something more going here because I cloned the Duwmaish system and didn't use a project template. For example I could not get this line to work:

System.Configur ation.Configura tionSettings.Ge tConfig("Applic ationConfigurat ion");

It kept saying it didn't like this web.config section:
<configSections >
<section name="Applicati onConfiguration " type="JCart.Sys temFramework.Ap plicationConfig uration, JCart.SystemFra mework" />

I'm not sure if that's related. I don't think it likes the "ApplicationCon figuration" word and somehow treats it differently because of the template but that's just a guess.

To answer your question:

It hits this code only the first time it's run after restarting IIS:
global.asax:App lication_Start
ApplicationConf iguration.OnApp licationStart(C ontext.Server.M apPath( Context.Request .ApplicationPat h ));

then,
public class ApplicationConf iguration : IConfigurationS ectionHandler
ApplicationConf iguration:JCart .SystemFramewor k::OnApplicatio nStart
System.Configur ation.Configura tionSettings.Ge tConfig("JCartC onfiguration");

then it creates the NameValueCollec tion settings,
public class JCartConfigurat ion : IConfigurationS ectionHandler
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollec tion settings;
try
{
NameValueSectio nHandler baseHandler = new NameValueSectio nHandler();
settings = (NameValueColle ction)baseHandl er.Create(paren t, configContext, section);
}

dbConnectionStr ing = ApplicationConf iguration.ReadS etting(settings , DATAACCESS_CONN ECTIONSTRING,
DATAACCESS_CONN ECTIONSTRING_DE FAULT);
}
return settings;
}

then, the ApplicationConf iguration.ReadS etting is this:
public static String ReadSetting(Nam eValueCollectio n settings, String key, String defaultValue)
{
Object setting = settings[key];
return (setting == null) ? defaultValue : (String)setting ;
return defaultValue;
}

So finally JCartConfigurat ion returns setting to this Create method
public class ApplicationConf iguration : IConfigurationS ectionHandler
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollec tion settings;
"Jon Skeet" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com... Not Available <no**********@b .com> wrote:
The connection string is initialized from a web.config file.


I meant where is the connection string initialised, as in "in which
method". It looks like it's only initialised when the Create method is
called. Why not initialise it when the type is initialised instead?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6
get a bigger scope

"Not Available" <no**********@b .com> wrote in message
news:ul******** *************@t wister.nyc.rr.c om...
I meant where is the connection string initialised, as in "in which
method". It looks like it's only initialised when the Create method is
I see your point. I don't think it is initialized anywhere else. I'm just
guessing but somehow JCartConfigurat ion.ConnectionS tring when used
non-remotley must pick up some left over private variable/instance but that
doesn't happen when the object trying to use
JCartConfigurat ion.ConnectionS tring is remote. I'm not sure if this
"NameValueColle ction settings" object from the IConfigurationS ectionHandler
is instantiated anywhere and thought it was part of the whole configuration
handler functionality. The whole concept of the Duwamish remote
business_facade :CustomerSystem MarshelByRef is to totally encapsulate
everything and to make it completly stateless. That's why I thought the
whole IConfiguration base class would somehow let you use the configuration
stuff it reads from web.config in all remote objects. It seems to work that
way in the remote setup of the Duwamish sample. Since I basically cloned the
code without the project template and couldn't get the <section
name="Applicati onConfiguration " part to work I thought it had something to
do with that.

I guess I should make some time to do a pared down example of this.
Basically I think the 'know how' I'm looking for is how to make
configuration settings available to a stateless remote completly encasulated
class. It looked like IConfigurationS ectionHandler woudl do that.
called. Why not initialise it when the type is initialised instead?
I might be misreading your question but I think the answer is because I want
the remote class/dll/object to be totally encapsulated and stateless.

Here are some other thoughts:

I think there's something more going here because I cloned the Duwmaish
system and didn't use a project template. For example I could not get this
line to work:

System.Configur ation.Configura tionSettings.Ge tConfig("Applic ationConfigurat i
on");

It kept saying it didn't like this web.config section:
<configSections >
<section name="Applicati onConfiguration "
type="JCart.Sys temFramework.Ap plicationConfig uration, JCart.SystemFra mework"
/>

I'm not sure if that's related. I don't think it likes the
"ApplicationCon figuration" word and somehow treats it differently because of
the template but that's just a guess.

To answer your question:

It hits this code only the first time it's run after restarting IIS:
global.asax:App lication_Start
ApplicationConf iguration.OnApp licationStart(C ontext.Server.M apPath(
Context.Request .ApplicationPat h ));

then,
public class ApplicationConf iguration : IConfigurationS ectionHandler
ApplicationConf iguration:JCart .SystemFramewor k::OnApplicatio nStart
System.Configur ation.Configura tionSettings.Ge tConfig("JCartC onfiguration");

then it creates the NameValueCollec tion settings,
public class JCartConfigurat ion : IConfigurationS ectionHandler
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollec tion settings;
try
{
NameValueSectio nHandler baseHandler = new NameValueSectio nHandler();
settings = (NameValueColle ction)baseHandl er.Create(paren t,
configContext, section);
}

dbConnectionStr ing = ApplicationConf iguration.ReadS etting(settings ,
DATAACCESS_CONN ECTIONSTRING,
DATAACCESS_CONN ECTIONSTRING_DE FAULT);
}
return settings;
}

then, the ApplicationConf iguration.ReadS etting is this:
public static String ReadSetting(Nam eValueCollectio n settings, String key,
String defaultValue)
{
Object setting = settings[key];
return (setting == null) ? defaultValue : (String)setting ;
return defaultValue;
}

So finally JCartConfigurat ion returns setting to this Create method
public class ApplicationConf iguration : IConfigurationS ectionHandler
public Object Create(Object parent, object configContext, XmlNode section)
{
NameValueCollec tion settings;
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Not Available <no**********@b .com> wrote:
The connection string is initialized from a web.config file.


I meant where is the connection string initialised, as in "in which
method". It looks like it's only initialised when the Create method is
called. Why not initialise it when the type is initialised instead?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
[If you could get your newsreader to wrap at about 72 columns, it would
make your posts much easier to reply to.]

Not Available <no**********@b .com> wrote:
called. Why not initialise it when the type is initialised instead?


I might be misreading your question but I think the answer is because
I want the remote class/dll/object to be totally encapsulated and
stateless.


Well it's not - it's clearly got state. If you wanted it to be
stateless, you'd need to declare it as a constant. The state in
question is "have I loaded in my configuration settings, and if so what
are they?". I don't see how you can have something loaded at runtime
but still stateless.

I'm not entirely sure how all of this works over remoting (I haven't
done much remoting at all) but I think you need to seriously think
about what you actually mean when you say you want the class to be
stateless.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
Yes, I guess I'm a bit off with the 'stateless' terminology. Stateless in
terms of the Duwamish example, means that no persistant database connection
is left open or required. The DataAccess layer object is also de-referenced
after it returns the information required. You are also correct that I'm
really not working with a specification, plan or design on what I want to
do. I picked apart the Duwamish sample as a tool to learn C# and an entry to
learning muiti-tier design. Reading the configuration file and having that
information available globally in static fields seems like the general
concept of what I'm trying to do.
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
[If you could get your newsreader to wrap at about 72 columns, it would
make your posts much easier to reply to.]

Not Available <no**********@b .com> wrote:
called. Why not initialise it when the type is initialised instead?


I might be misreading your question but I think the answer is because
I want the remote class/dll/object to be totally encapsulated and
stateless.


Well it's not - it's clearly got state. If you wanted it to be
stateless, you'd need to declare it as a constant. The state in
question is "have I loaded in my configuration settings, and if so what
are they?". I don't see how you can have something loaded at runtime
but still stateless.

I'm not entirely sure how all of this works over remoting (I haven't
done much remoting at all) but I think you need to seriously think
about what you actually mean when you say you want the class to be
stateless.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #9
Not Available <no**********@b .com> wrote:
Yes, I guess I'm a bit off with the 'stateless' terminology. Stateless in
terms of the Duwamish example, means that no persistant database connection
is left open or required.
Right - that really *is* different from what I understand by the wor
d"stateless" :)
The DataAccess layer object is also de-referenced
after it returns the information required. You are also correct that I'm
really not working with a specification, plan or design on what I want to
do. I picked apart the Duwamish sample as a tool to learn C# and an entry to
learning muiti-tier design. Reading the configuration file and having that
information available globally in static fields seems like the general
concept of what I'm trying to do.


One thing you could do is change dbConnection to be a property, and
make the property check whether or not the configuration has been
loaded before it returns a value.

As an aside, if this is really the way you plan to *learn* C#, I'd
suggest a completely different approach - start with very simple
console apps, and work up. IMO, there's no point in looking at ASP.NET
and database access until you're happy with the fundamentals.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2325
by: pranab_bajpai | last post by:
So I want to define a method that takes a "boolean" in a module, eg. def getDBName(l2): .... Now, in Python variables are bound to types when used, right? Eg. x = 10 # makes it an INT whereas
2
3295
by: Jeff S | last post by:
In a VB/ASP.NET project, the following lines work as advertised when placed in a code-behind file (whatever.aspx.vb) - meaning that I get the full physical path to MyDatabase.MDB in the variable PathToMDB. However, when the same two lines are moved to a separate class file (whatever.vb), the project fails to build - with the message "Name 'Server' is not declared." Dim PathToMDB As String PathToMDB = Server.MapPath("/MySite/db/") +...
1
1475
by: Just Me | last post by:
Given a file containing Multiple classes and a variable that needs to be seen in all the classes I can put it in one of the classes as Shared and reference it the other classes as TheOneItsIn.Variable But is there a way to give a variable Module scope so it can be used in all the classes without a prefix? Thanks
10
4602
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which Product Is Null. SELECT COUNT(*) AS CountofNullProdcut
5
1740
by: Newbie in ChiTown | last post by:
I created a subprocedure that includes a recordset as follows: Private Sub Combo17_Click() 'Declaring object and string variables Dim DB As Database Dim rec As Recordset Dim sDealName As String 'Assign Object variable to current database
3
1494
by: Greg | last post by:
this template won't compile when used with bool, the erorr is "invalid initialization of non const reference" template < typename T > class Vec : public std::vector< T { public: Vec() { } Vec( int s ) : std::vector<T>(s) { } T& operator(int i) { return this -at(i); } // <- this line
3
1222
by: zybonje | last post by:
how can i make a global variable that can be used in all forms of my projects
1
1544
by: 22dude | last post by:
it says the variable hours is being used with out being initializes i am using C++ 2005 express edition , I am currently student Please help me out to find the solution on my code below # include <iostream> using namespace std; # include <string> int main ()
3
1644
by: raylopez99 | last post by:
Oh, I know, I should have provided complete code in console mode form. But for the rest of you (sorry Jon, just kidding) I have an example of why, once again, you must pick the correct entry point in your code when adding a class (oops, I meant variable, or instantiation of a object that's a class) to a form constructor. Specifically, adding a class variable should always come BEFORE the statement "InitializeComponent()" in your form...
0
11283
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10875
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10986
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7206
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6093
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4727
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.