473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Structural question regarding scope of variables

Hi group,

I've been developing a number of classes, many of which have a similar
structure, as follows:

namespace
{
public class classname
{
Private Fields
private readonly static string connString =
ConfigurationManager.ConnectionStrings["SCMConnectionString"].ConnectionString;

Public Fields

Public Properties

Private Instance Methods

Public Instance Methods

Public Static Methods
// these methods use the connString variable to establish database
connections, using Microsoft.ApplicationBlocks.Data
}
}

However, the static connString is declared in every class. I'm
currently only using one connection, but I foresee using 2 or 3
different connection strings, based on where the data will need to
come from.
Can anyone suggest a better way of doing this, so that I don't have to
declare this variable in every class?
Note that I had considered using inheritance by basing all the classes
that need data on a base class that contains the static connection
string. However, that doesn't seem the right approach because I only
want to achieve the effect of a global variable. Speaking of global
variables, note that I'm targeting a web environment.

Any thoughts on this?

Aug 1 '07 #1
1 1158
Hi,
"Froefel" <ha************@gmail.comwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
Hi group,

I've been developing a number of classes, many of which have a similar
structure, as follows:

namespace
{
public class classname
{
Private Fields
private readonly static string connString =
ConfigurationManager.ConnectionStrings["SCMConnectionString"].ConnectionString;
However, the static connString is declared in every class. I'm
currently only using one connection, but I foresee using 2 or 3
different connection strings, based on where the data will need to
come from.
Can anyone suggest a better way of doing this, so that I don't have to
declare this variable in every class?

Any thoughts on this?
A better approach would be to create a new class, static class, to just hold
the connection string needed. In case that you have more than one connection
then it will be up to the class to determine which one to use. That will
depend of how you divide the data and how the classes how where the data
they need is.
Aug 1 '07 #2

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

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
6
by: pembed2003 | last post by:
Hi all, I am reading the book "C++ How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
10
by: davidrubin | last post by:
Structural inheritance (inheriting implementation) is equivalent to composition in that a particular method must either call 'Base::foo' or invoke 'base.foo'. Apparantly, The Literature tells us to...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
9
by: sam_cit | last post by:
Hi everyone, I have the following piece of code, #include <stdio.h> #include "sample1.h" int x = 10; namespace first
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.