1

I am building app using ASP.NET Core 2 and DB part is EF core 2.

i have model like this

public class User        
{
     public int Id { get; set; }
     public string FirstName { get; set; }
     public string LastName { get; set; }   
}

This is context file

public class EFCoreDbContext:DbContext
{
    public EFCoreDbContext(DbContextOptions<EFCoreDbContext> options)
    : base(options)
    {

    }

    public DbSet<ChatMessage> ChatMessages { get; set; }
}

and finally startup.cs

services.AddDbContext<EFCoreDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("MooltiRoomDatabase")));

And connection string in appsettings.json

"ConnectionStrings": {
    "MooltiRoomDatabase": "Server=DESKTOP-BCQ6IAU\\CHATDB,Database=MultiRoomChat;Trusted_Connection=True;"
  }

Through package manager console i was runing Add-Migration the command completed successfully despite the fact that in DB it did not create corresponding table,after that i've read that i need to run Update-Database command for creating table and when i run this command, i got a error like this

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: 25 - Connection string is not valid)

2 Answers 2

3

As you can see in the error message, 'Connection string is not valid.' You used "," instead of ";" before the Database.

So now you have:

"Server=DESKTOP-BCQ6IAU\\CHATDB,Database=MultiRoomChat;Trusted_Connection=True;"

But, you should use this:

"Server=DESKTOP-BCQ6IAU\\CHATDB;Database=MultiRoomChat;Trusted_Connection=True;"
Sign up to request clarification or add additional context in comments.

Comments

0

In ASP Net Core there is also a development configuration that gets used. You should notice an icon next to app settings - the "drop down" icon. See if adding your connection string to the development config helps.

Also the way the app settings get accessed has changed so make sure you are writing the correct code to receive the value.

Comments

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.