Entityframework Core 5 does not connect to SQL Server 2008

Asked

Viewed 24 times

0

I installed dotnet core 5 on Ubuntu 21.04. I created a webapi project with VS Code and managed to run everything smoothly.

I installed EF5 to the project and am trying to connect to SQL Server 2008

Dbcontext

using Microsoft.EntityFrameworkCore;

namespace Models
{
    public partial class Banco : DbContext
    {
        public virtual DbSet<Cliente> Cliente { get; set; }
        public Banco() : base()
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=<<servidor>>; Database=<<banco>>; User Id=<<user>>; Password=<<senha>>;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            modelBuilder.Entity<Models.Cliente>()
                .HasKey(c => new { c.codcli });

        }

    }

}

Model

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Models
{
    public partial class Cliente
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int codcli { get; set; }

        public string nomcli { get; set; }

    }
}

Controller

using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Data.SqlClient;
using System;

namespace dotnetc_webapi.Controllers
{
    [ApiController]
    [Route("")]
    public class DefaultController : ControllerBase
    {
        [HttpGet]
        public dynamic Get()
        {
            Models.Banco banco = new Models.Banco();
            var cliente = banco.Cliente.Take(10).Select(cli => cli).ToArray();
            return new OkObjectResult(cliente);

        }
    }
}

When running the project with the command dotnet watch run it opens the browser and while trying to connect to the bank shows the following error:

SqlException: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

on the line var cliente = banco.Cliente.Take(10).Select(cli => cli).ToArray();

What I find strange is that if I take the same project without any change in the code and run inside Windows 10 it can connect to the database and receive data from customers normally and in Ubuntu no.

I’ve tried these procedures and nothing https://docs.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/default-cipher-suites-for-tls-on-linux

I don’t know if this is the right way or I’m missing something.

I am dependent on windows just because of this project, I have to use a VM to run windows because of it. I would love to solve this problem and only use linux.

  • and how is connecting to the bank, with IP, name? already tested the same connection in another client, in management studio for example?

  • I use a ddns.net domain to connect to the server. If I use it in Windows, the project can connect to the database and receive the data. In Ubuntu using dotnet does not work. Inside Ubuntu I use another client the Navicat and it can connect normally.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.