2017-01-04 4 views
-1

.net 핵심 기술을 사용하고 있는데 새 데이터베이스를 만들 때 오류가 발생합니다.Asp.Net 핵심 데이터베이스 만들기

이것은 내 NorthwindContext 클래스이며 여기서 서버 위치를 쓰고 있습니다.

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; } 
    } 

그리고 나는이 무엇입니까 콘솔 프로젝트와 결과에

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); 
      } 
     } 
    } 

을 데이터베이스를 만들려면 : " 'System.Data.SqlClient.SqlException'는 마이크로 소프트에서 발생 유형의 처리되지 않은 예외 .EntityFrameworkCore.dll.

추가 정보 : 'sa'사용자가 로그인하지 못했습니다. "

나는 당신의 도움을 기다리고 있습니다. 미리 감사드립니다.

답변

2

오류 메시지에 실제로 충분한 정보가 들어 있습니다.

사용하는 대신 사용자 이름 & 암호 trustedconnection로 connectionsting " 'sa'사용자가 로그인하지 못했습니다."

그것은 같이 보인다 :

connectionString="Server=(localdb)\mssqllocaldb;Database=Northwind;Trusted_Connection=True;"