0

I'm working on an ASP.NET Framework Web App. I have decided to move my connectionStrings from the default web.config file to an external file, for safety reasons etc. The web.config and the external file are linked together with the configSource attribute.

This works fine when I'm debugging the app locally. When I try to publish the app however, I get the error message: "The 'Entities-Web.config Connection String' argument cannot be null or empty."

For the external file, I have set Build Action = Content and Copy to Output Directory = Copy always.

This is in my web.config file:

  <connectionStrings configSource="ConnectionStrings.config">
  </connectionStrings>

This is the ConnectionStrings.config file:

<?xml version="1.0" encoding="utf-8"?>
  <connectionStrings>
    <add name="Entities" connectionString="somestring" providerName="System.Data.EntityClient" />
  </connectionStrings>

What can I do to make the connectionStrings load properly when publishing?

Vidar
  • 13
  • 3

1 Answers1

0

You could refer to similar SO thread and use the steps as below.

1.After publishing your project, select the Configure tab.

enter image description here

2.Uncheck the use this connection string at runtime from all your connection strings.

enter image description here

3.Click Save and try to publish the website again.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Thanks, I will try that. Do you know why the configSource doesn't work when publishing tho? Seems like kind of a dumb feature if it only works in debug mode. – Vidar Sep 11 '19 at 07:06
  • If you click the option as I provided, it will override the connectionstring in web.config. So, the configSource will not work. – Joey Cai Sep 11 '19 at 07:08
  • I haven't had the time to test it yet, sorry. I'll get back to you when I have – Vidar Sep 16 '19 at 07:06