Skip to content
Advertisement

JSON Connection string configuration

In the app settings JSON file I am passing through a connection string which contains the name of my server
‘ .SQL2017 ‘

I recieve the following warning in error list when entering the server name verbaitam as so in the connection string

‘Invalid escape sequence’

When I then run the ‘dotnet ef database update’ command in the terminal I get the error

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not parse the JSON file.

When I take away the . from the connection string to remove the warning for ‘Invalid escape sequence I get passed the error above and am then faced with the error

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 conf
igured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

I am sure that the rest of my connection string properties are correctly entered with no warnings but I am not sure how to format the server name in the connection string in a JSON format so that it can accept without any errors

Advertisement

Answer

Double the backslash to escape it:

.\SQL2017

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement