.net SqlClient and .NET CORE Web API connection string

.net asp.net-core c# entity-framework entity-framework-core


Is it me or tis there a different way that sqlclient and .net core uses the connection string.

example old client:

var connectionString = "Data Source=SQLSERV1\\SQLSERV1;Initial Catalog=mydb;User ID=myuser; Password=mypass;";
using (SqlConnection conn = new SqlConnection(connectionString))

Code works fine, results come back from this sql client query.

Now in .NET CORE web API :


"Data": {
    "DefaultConnection": {
        "ConnectionString": "Data Source=SQLSERV1\\SQLSERV1;Initial Catalog=mydb;User ID=myuser; Password=mypass;"


public void ConfigureServices(IServiceCollection services)

        .AddJsonOptions(config =>
            config.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    services.AddDbContext<MW_MereSysContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

when i try to nav to the url in my browser i get:

An unhandled exception occurred while processing the request.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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

So how is it that sqlclient sees the server fine, but .net core cannot? is it the way it process the string i.e the fact its on a domain?

12/21/2016 12:25:20 PM

Popular Answer

Maybe it's a syntax problem:

Data Source=Server\\Instance

If you have a default instance, then, only use:

Data Source=Server
5/17/2018 6:53:34 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow