Re: Global variable alternative?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 6 Oct 2005 17:18:42 +0800, "Newbie" <d> wrote:

>
>Hello,
>
>I need to declare a global variable e.g. database connection handle. So that
>I hava an access to this variable all over my class. How can I do it in c#?
>Do I have to declare it as static ?
>Thanks for any help.
>

It depends, static shares a variable between all instances of a class.

Do you have a single instance of your database class that you reuse
for each database call? In that case static isn't needed.

Do you create a new instance of your database class each time you call
the database? In that case you have to use a private static variable.

--
Marcus Andrén





--
Marcus Andrén
.



Relevant Pages

  • run stored proc from excel with a parameter
    ... declare @sql nvarchar ... [Database Name] ... [Custodian Name] ... [Near Dups File Count] ...
    (microsoft.public.excel.programming)
  • Re: CDatabase CRecordset - How to get the number of rows?
    ... What is the value of dataStr in the CRecordset::Open call. ... > // Declare a long to hold the row count for the fast method ... > // Declare a long to hold the row count for the slow method ... >>> I'm now testing my DLL with the real database. ...
    (microsoft.public.vc.mfc)
  • Re: Update databases
    ... Compares if all tables in one database have analog in second ... declare @sqlStr varchar ... exec ('declare @Name sysname select @Name=name from ... -- ##CompareStr - will be used to pass comparing strings into dynamic script ...
    (microsoft.public.sqlserver.programming)
  • Re: great script, but...
    ... DECLARE @x nvarchar; ... I am having 'n' number of tables within a database. ... open boris ... Can't we avoid using cursors? ...
    (microsoft.public.sqlserver.programming)
  • Looking for data dictionary/definition integrity checking utility
    ... This script searches for a value in the database. ... declare @tbl varchar ... -- char and numeric ... open CRR ...
    (microsoft.public.sqlserver.programming)