我正在尝试从我的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.)
我不确定为什么要测试服务器浏览器与数据库的连接,并且连接成功。
有人知道我在做什么错吗?