0

I have an .net core app and I'm trying to use with EntityFrameworkCore to build the db but when I do:

update-database

This error shows up:

Format of the initialization string does not conform to specification starting at index 0.

I've changed my connection string to a standard format and tried this because I had an error because the assembly of my main project wasn't the same as the library I'm using for classes:

services.AddDbContext<conn>(options => options.UseSqlServer("connname", b => b.MigrationsAssembly("conn")));


"ConnectionStrings": {
"FITMEConnection": "Server=foo;Database=fooname;Trusted_Connection=True"
},

I'm getting mad about this because I've searched this error and seems simple to solve. What am I doing wrong? Thank you.

1 Answer 1

1

First your appsettings.json file should look like as follows:

{
  "ConnectionStrings": {
    "FITMEConnection": "Server=foo;Database=foo;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Then do as follows:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        var connectionString = Configuration.GetConnectionString("FITMEConnection"); // <-- Look at here

        services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString),b => b.MigrationsAssembly("MigrationAssemblyName")); 
   }
}

Now it should work!

Sign up to request clarification or add additional context in comments.

6 Comments

I'm getting this error now: 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)
That means your connection string is not valid! Please recheck it.
@AntónioA Are you still getting the issue?
Yes. My connection string is as you mentioned
@AntónioA Has not been solved yet! May be you are missing the right server name. Which version of sql server is installed on your machine?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.