Click here to Skip to main content
15,860,943 members
Home / Discussions / C#
   

C#

 
QuestionMy winform resize when i open an OleDbConnection Pin
Le@rner27-Nov-22 18:42
Le@rner27-Nov-22 18:42 
AnswerRe: My winform resize when i open an OleDbConnection Pin
Pete O'Hanlon27-Nov-22 21:30
subeditorPete O'Hanlon27-Nov-22 21:30 
QuestionConcurrent Containers Pin
Richard Andrew x6424-Nov-22 14:47
professionalRichard Andrew x6424-Nov-22 14:47 
AnswerRe: Concurrent Containers Pin
Richard Deeming24-Nov-22 22:02
mveRichard Deeming24-Nov-22 22:02 
GeneralRe: Concurrent Containers Pin
Richard Andrew x6425-Nov-22 2:18
professionalRichard Andrew x6425-Nov-22 2:18 
AnswerRe: Concurrent Containers Pin
Gerry Schmitz25-Nov-22 5:10
mveGerry Schmitz25-Nov-22 5:10 
GeneralRe: Concurrent Containers Pin
Richard Andrew x6425-Nov-22 5:24
professionalRichard Andrew x6425-Nov-22 5:24 
QuestionEntity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 9:01
professionalKevin Marois24-Nov-22 9:01 
I'm using EF 6 Core Code First. I'm trying to set up some basic code and I'm getting an exception at runtime.

Here's my Context class:
using Microsoft.EntityFrameworkCore;

namespace EFCoreDBFirstExample.Models
{
    public partial class ModelContext : DbContext
    {
        public virtual DbSet Departments { get; set; }
        public virtual DbSet Employees { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionString = @"Server=MAROIS_KEVIN_1\SQLEXPRESS;Database=Test;Trusted_Connection=true;Encrypt=false;";
            optionsBuilder.UseSqlServer(connectionString, options => options.EnableRetryOnFailure());
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity(entity =>
            {
                entity.ToTable("Departments", "public");

                entity.HasKey(e => e.DepartmentId)
                      .HasName("DeptartmentId");

                entity.Property(e => e.DepartmentId)
                      .HasColumnName("DeptartmentId");

                entity.Property(e => e.DepartmentName)
                    .HasColumnName("DepartmentName")
                    .HasColumnType("varchar")
                    .HasMaxLength(30);
            });

            modelBuilder.Entity(entity =>
            {
                entity.ToTable("EmployeeName", "public");

                entity.HasKey(e => e.EmployeeId)
                      .HasName("EmployeeId");

                entity.Property(e => e.EmployeeId)
                      .HasColumnName("EmployeeId");

                entity.Property(e => e.EmployeeName)
                    .HasColumnName("EmployeeName")
                    .HasColumnType("varchar")
                    .HasMaxLength(30);
            });
        }
    }
}
Here's how I'm using it
using EFCoreDBFirstExample.Models;

using (var db = new ModelContext())
{
    // Creating a new department and save it to the database
    var newDept = new Departments();
    newDept.DepartmentId = 1;
    newDept.DepartmentName = "Development";

    db.Departments.Add(newDept);
    var count = db.SaveChanges(); //<======================= ERROR HERE

    Console.WriteLine("{0} records saved to database", count);

    // Retrieve and display the data
    Console.WriteLine();
    Console.WriteLine("Departments:");
    foreach (var dept in db.Departments)
    {
        Console.WriteLine($"{dept.DepartmentId}: {dept.DepartmentName}" );
    }

    Console.ReadLine();
}

Here's the exception:
Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
  HResult=0x80131500
  Message=The maximum number of retries (6) was exceeded while executing database operations with 'SqlServerRetryingExecutionStrategy'. See the inner exception for the most recent failure.

Inner Exception 1:
SqlException: Cannot open database "Test" requested by the login. The login failed.
Login failed for user 'MAROIS_KEVIN_1\kevin'.

As you can see, I'm using Trusted Connection in my connection string. Not sure why EF is trying to connect with the user 'kevin'.

I could use some help here. Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 9:41
mveDave Kreskowiak24-Nov-22 9:41 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 10:19
professionalKevin Marois24-Nov-22 10:19 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 14:48
mveDave Kreskowiak24-Nov-22 14:48 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois24-Nov-22 15:57
professionalKevin Marois24-Nov-22 15:57 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak24-Nov-22 16:03
mveDave Kreskowiak24-Nov-22 16:03 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois25-Nov-22 19:16
professionalKevin Marois25-Nov-22 19:16 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 5:20
mveDave Kreskowiak26-Nov-22 5:20 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 9:20
professionalKevin Marois26-Nov-22 9:20 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 9:24
mveDave Kreskowiak26-Nov-22 9:24 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 10:24
professionalKevin Marois26-Nov-22 10:24 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak26-Nov-22 11:31
mveDave Kreskowiak26-Nov-22 11:31 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois26-Nov-22 11:50
professionalKevin Marois26-Nov-22 11:50 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois27-Nov-22 7:56
professionalKevin Marois27-Nov-22 7:56 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak27-Nov-22 8:38
mveDave Kreskowiak27-Nov-22 8:38 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois27-Nov-22 9:16
professionalKevin Marois27-Nov-22 9:16 
GeneralRe: Entity Framework Core 6 Problem Pin
Kevin Marois27-Nov-22 9:31
professionalKevin Marois27-Nov-22 9:31 
GeneralRe: Entity Framework Core 6 Problem Pin
Dave Kreskowiak27-Nov-22 9:32
mveDave Kreskowiak27-Nov-22 9:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.