无法从数据库获取数据

时间:2018-08-23 18:54:24

标签: database model-view-controller

我正在尝试从我的ProductService.cs类中的数据库中的表中检索数据:

public class ProductService
{
    private DataModel db = new DataModel();

    public List<Product> GetAllProducts()
    {
        return db.Products.ToList();
    }

}

但是当调用GetAllProducts方法时,出现了这个异常:

A network-related or instance-specific error occurred while 
establishing a connection to SQL Server. The server was not found or 
was not accessible. Verify that the instance name is correct and that 
SQL Server is configured to allow remote connections. (provider: SQL 
Network Interfaces, error: 50 - Local Database Runtime error occurred. 
Cannot create an automatic instance. See the Windows Application event 
log for error details.)

我不确定为什么要测试服务器浏览器与数据库的连接,并且连接成功。

有人知道我在做什么错吗?

0 个答案:

没有答案