Search code examples
c#.net-coreentity-framework-coreasp.net-core-scaffolding

Scaffold-DbContext Instance failure - create models from existing database (project with Individual Identity)


I created a database with few tables like user, userRole, role and I created project in .net Core with EFCore5 with Individual Identity. I tried to run

Scaffold-DbContext 'Server=\;database=___;Trusted_Connection=True;MultipleActiveResultSets=true' Microsoft.EntityFrameworkCore.SqlServer

to generate models but I get this error:

System.InvalidOperationException: Instance failure. at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) Instance failure.

  public class ApplicationDbContext : ApiAuthorizationDbContext<ApplicationUser>
{
    public ApplicationDbContext(
        DbContextOptions options,
        IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
    {
    }
}

Solution

    1. Services -> SQL Server Browser - turn on
    2. Windows Firefall -> Inbound Rule -> New Rule - Port, TCP, All local ports, Allow the connection -> Add
    3. In this role propperties -> protocols and ports -> Protocol Type - All
    4. Sql server 20** Configuration Manager -> SQL Server Network Configuration -> TCP/IP -> IP Adsress -> Enabled - yes | TCP dynamic posts - empty | TCP Port - 1433
    5. Services - restart Sql server

    Also thanks for advice to use EF Core Power Tools.