vinnie wrote:
i'm at the very beginning, and while trying to use the following small
code, i got an error msg thta said use the "new" keyword to create an
object instance.
It's lying to you.
:)
Well, actually...it might be that the error includes other information.
But if all it says is to use "new", then at least based on the line of
code you posted it doesn't appear that advice is correct.
Actually, since i'm at the very beginning, i don;t really know hot to
change it. This is the code:
string strConnectionSt ring =
ConfigurationMa nager.Connectio nStrings["SqlConnectionS tring"].ConnectionStri ng;
I haven't used that part of the API, but it should just work fine as
you've posted the code.
The ConnectionStrin gs property returns a
ConnectionStrin gSettingsCollec tion and using the ["SqlConnectionS tring"]
indexer on it should return a ConnectionStrin gSettings instance, which
has a ConnectionStrin g property that is of the type string.
In other words, the line of code should return a string and assign it to
your variable "strConnectionS tring". (All of that assumes the
"SqlConnectionS tring" identifies an actual item in the collection, but
that wouldn't be a compile-time error in any case).
So...
Given that the code posted should work, there must be something else you
didn't describe about the code that's causing a problem. For best
results, you should post a concise-but-complete example of code that
reproduces the compiler error. Emphasis on "concise".
But, before you do that, you should check to make sure that you have
actually added System.Configur ation as a reference for your project
(some namespaces require explicitly being added as a reference, some are
already in the default references). I can see how you'd get a compiler
error that tries to be helpful about how to instantiate a string if the
problem was actually that the compiler wasn't aware of the API you're
trying to use.
If that's not the problem, then along with the example of code I suggest
above, you should also post the _exact_ text of the error. Error
messages have very specific details within them that often can lead
directly to a solution. But we can only offer that solution if you post
those exact details.
Pete