Ich verwende. NET-Core-Technologie und ich bekomme einen Fehler, wenn ich neue Datenbank erstellen möchte.Asp.Net Core Erstellen von Datenbank
Dies ist meine NorthwindContext-Klasse, ich schreibe Serverstandort hier.
public class NorthwindContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Northwind;Persist Security Info=True; User ID=sa; Password=xxxxxxxx");
}
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
}
Und ich mag Datenbank erstellen mit Konsolenprojekt
public class Program
{
public static void Main(string[] args)
{
NorthwindContext context = new NorthwindContext();
Product product1 = new Product() {ProductId = 1, CategoryId = 1, ProductName = "Asus Notebook", UnitPrice = 5000, UnitsInStock = 100};
context.Products.Add(product1);
context.SaveChanges();
var products = context.Products.OrderBy(p => p.ProductName);
foreach (var product in products)
{
Console.WriteLine(product.ProductName);
}
}
}
Im Ergebnis erhalte ich diese: „Eine nicht behandelte Ausnahme des Typs‚System.Data.SqlClient.SqlException‘in Microsoft aufgetreten .EntityFrameworkCore.dll.
Weitere Informationen: Anmeldung fehlgeschlagen für Benutzer 'sa'. "
Ich warte auf Ihre Hilfe, danke im Voraus.