3

I have written a very simple test API in .net core 3.1. I've almost got it working, but I just can't seem to get past this "SQLServerException: Login failed for user" migration problem at update-database.

The add-migration command is working properly and the migration file was created. I created a simple database StudentData, but was unable to connect to the database. I am using SSMS 18 on Win 10.

"ConnectionStrings": {
"DBString": "Data Source=PUNIT;Initial Catalog=StudentData;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"  } 

Context File

public class DContext : DbContext
{
    public DContext(DbContextOptions<DContext> options) : base(options)
    {
    }
    public DbSet<Student> Student { get; set; }
    public DbSet<DictionaryExa> DictionaryExa { get; set; }
}
Ataxias
  • 1,085
  • 13
  • 23
Kanet punit
  • 97
  • 11

1 Answers1

0

It sounds a bit like you've tried a couple of solutions yourself. Does the error message come from an exception through your code or through ssms?

You aren't logging into ssms with your connection string, correct?, but probably with sql server authentication.

have you made sure you have created a user with correct credentials through ssms, and have you made sure that the user has permissions to the database?

you should be able to see this in the
server -> security -> logins -> {yourUser}
or
{DatabaseName} -> Properties -> Permissions

Make sure that you can log on to ssms with the user and then modify your connection string to be more in line with

"Server={ServerName};Database={DatabaseName};Trusted_Connection=false;User={username};Password={password};/*rest of configuration properties*/..."

If you are uncertain about how to generate a user through ssms, here's a link to a guide on ibm on how to create one with sql server authentication. https://www.ibm.com/support/knowledgecenter/SSMKFH/com.ibm.apmaas.doc/install/sql_config_agent_grant_permission_sqlserver.html

Bjarke Handsdal
  • 219
  • 1
  • 6