This is repeated from the .Net Core thread but I copied here because it has nothing to do with .Net Core. It's a newbie question.
The connection string is always empty. I overrode it for now (I hard-coded it in ReadConnectionStringFromConfig() in DataAccessAdapter in _Project_DBSpecific). I read that I need to copy the app.config but that did not work. I basically inserted the connection string in all the *config files (including web.Debug.config and web.Release.config) with no success. I also read somewhere that a "webapp does not read the config file automatically". Not sure if this is related.
I got some help:
WayneBrantley wrote:
In startup.cs, in ConfigureServices:
CommonDaoBase.ActualConnectionString = Configuration.GetConnectionString("StringName");
This is for SelfServicing, I am sure adapter is similar. You do not have a 'web.config' to load settings from, so that is why it is not automatically loaded anymore with asp.net core.
Thank you Wayne, but even with this help I can't figure it out
(I'm using adapter and I'm not using asp.net core - as per Frans suggestion in the thread I am using .net 4.5.2).
There is no startup.cs (is this normal?) but there is a Global.asax.cs. If I put
DataAccessAdapter.ConnectionStringKeyName = "ConnectionString.SQL Server (SqlClientXYZ)";
... in Global.asax.cs that's the value I see in ConnectionStringKeyName in ReadConnectionStringFromConfig() but it seems not to find the proper file to read it from.
Where is that file? What's its name? Or where would I insert the quoted line? I would guess it's different for Adapter? But there is no ActualConnectionString property in DataAccessAdapterBase.
I think I need more detailed information (apologies for trivial questions). Thanks.
Jezz! I figured it out! If this can help someone: The Connection strings are in the Web.config file! I put
DataAccessAdapter.ConnectionStringKeyName = "ConnectionString.SQL Server (SqlClientXYZ)";
... in Global.asax.cs and it read it from Web.Config (not web.Debug.config nor web.Release.config - I _though _web.config was generated from these 2 files).
Related: In the future, how can I find the problem to this kind of issue myself? For example if I F11 on
private static string ReadConnectionStringFromConfig()
{
return ConfigFileHelper.ReadConnectionStringFromConfig(ConnectionStringKeyName);
}
... I cannot see the code for ConfigFileHelper.ReadConnectionStringFromConfig. If I could see the code I could perhaps figure it out.** Is this the way to go ?** If so how do I get that source code?