How to override Connection string in appsettings.json

350540's Avatar

350540

22 Mar, 2018 01:50 PM

I have an asp.net core 2.0 web application worked fine at local sql server.

After publishing i become error:

Win32Exception: The network path was not found

Unknown location
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I set up connectionstring alias as described here: https://support.appharbor.com/kb/add-ons/using-sequelizer (this worked fine for my classic asp.net apps on appharbor)

Also I read again this topic: https://support.appharbor.com/discussions/problems/90387-is-net-cor... - user AHRocks told 'create Web.Config and inject this config into IHostingEnvironment'), but..
it also doesn't work: appharbor inject in web.config (i tried also Web.config - is file name case-sensitive?) some strings (system.webserver) but it can't see connectionString.

I'm puzzled. What is the right way?

It looks like that .net core at EU servers still has no injection: https://support.appharbor.com/discussions/problems/90851-net-core-c...

  1. Support Staff 1 Posted by rune on 26 Mar, 2018 11:39 PM

    rune's Avatar

    Hi,

    How do you initialize the connection string? AppHarbor doesn't currently replace the connection strings in json files, but I think it should be possible to do in a couple of ways:

    1. Set the .NET Core environment to Production as described here, and then configure the production environment to use the SQL Server add-on variable (e.g. SQLSERVER_CONNECTION_STRING) in that environment).
    2. Create a Configuration Variable on AppHarbor that'll override the connection string when the app is deployed since it's injected in the environment (in all regions), so try and create a configuration variable with the name ConnectionStrings:DefaultConnection (replacing DefaultConnection with the actual name of the connection string in your appsettings.json file) and the connection string as the value.

    Let me know if either of those approaches doesn't work!

    Best,
    Rune

Discussions are closed to public comments.
If you need help with AppHarbor please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac