Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why I can not make my Connection String a const?
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Why I can not make my Connection String a const?
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01349894
Message ID:
01349894
Views:
72
Hi everybody,

I was thinking that instead of accessing my connection string through configuration manager in several procedures of our global static class I'll make it a const property. So, based on another existing const I put
   private const string TelephoneRegex = @"(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT]| )\.?\s*(\d+))*";
    private const string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["FCCMSConnectionString"].ConnectionString;
at the very top of the class.

However, I'm getting this error

Error 1 'Util.ConnectionString' is of type 'string.' A const of reference type other than string can only be initialized with null

Do you know if this is a wrong approach? What can I do to use this as a property?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform