Click to See Complete Forum and Search --> : Reading App.cfg file in ref class


jjones7947
October 1st, 2009, 02:02 PM
Same managed C++ Windows Service project in VS2008.
Trying to read a db connection string from my app.cfg file (properly named of course)
use the following code:
<code>
//First get the database name out of AppSettings section
String^ database = ConfigurationManager::AppSettings["database"];
// Now get the connection string for that db
ConnectionStringSettingsCollection strings = ConfigurationManager::ConnectionStrings::get;
ConnectionStringSettings settings = strings.default[database];
String^ connString = settings.ConnectionString;
</code>
I get C3673 compiler errors on both ConnectionStringSettingsCollection and ConnectionStringSettings that "class does not have a copy-constructor"
What is that all about? BTW it's the same with and without the "::get".
Jim

Alex F
October 1st, 2009, 02:55 PM
Maybe you need ConnectionStringSettingsCollection^ and ConnectionStringSettings^.
BTW, why do you need to write service in C++/CLI? For managed service, C# is much better choice. Native service can be written in C++.
C++/CLI has very restricted area of using: interoperability between managed and unmanaged code.

jjones7947
October 1st, 2009, 03:50 PM
Ok did:
ConnectionStringSettingsCollection^ connectionStrings = ConfigurationManager::ConnectionStrings;
ConnectionStringSettings^ cSettings = connectionStrings.default[database];
connString = cSettings.ConnectionString;
This got me some new errors both of type C2228:
1. left of '.default' must have class/struct/union
2. left of '.ConnectionString' must have class/struct/union

Your Question:
don't have a good grasp of how to do it in unmanaged C++. Have done a lot in C# so have models. Most importantly, need to use some technology (managed or nmanaged I don't know) in a .lib file. This seems to be rather straight-forward even in managed C++, if I can get by some of these quirks.
Thanks,
Jim

Alex F
October 1st, 2009, 04:02 PM
My guess:
connectionStrings->default
cSettings->ConnectionString

jjones7947
October 2nd, 2009, 06:48 AM
Yep, that did it. I see, using managed code does not get you out of any of the normal C++ housekeeping. Is "." ever used in C++?
I keep seeing C2686 errors: cannot overload static and non-static member function with the same parameter types. I get this most recently on:
AseConnection conn = gcnew AseConnection(connString); where connString is declared as String^ connString = nullptr;
In looking on the web this may be related to some IDE setting. Any ideas?

Thanks,
again
Jim