Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why I can not make my Connection String a const?
Message
 
 
To
23/09/2008 14:50:16
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01349894
Message ID:
01349988
Views:
31
>Paul gave you a great suggestion, here is some code to do that. This is seperate from your static v instance issue. This way it is only in one place and retrieved only the first time it is accessed.
>
>public string ConnString
>{
>     get
>     {
>          if (_connString == "")
>          {
>               _connString = System.Configuration.ConfigurationManager.ConnectionStrings["FCCMSConnectionString"].ConnectionString;
>          }
>          return _connString;
>     }
>}
>private string _connString = "";
>
What is better and why, the way I currently have it in util.cs or the way you showed?

static readonly string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["FCCMSConnectionString"].ConnectionString;
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform