I understand that this error is duplicated and repeated a lot on the internet and especially on stack over flow. I have looked at the answers but known of them would help therefore, I would like to know the reason for this error. I will attache the error below along side with the code.
Connection String:
<connectionStrings>
<add name="sqlServer" connectionString="Server=xxxx;Initial Catalog=xxxx;Integrated Security=False;User ID=xxxx;Password=xxxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
DBContext:
public class DatabaseContext : DbContext
{
public DatabaseContext() : base("sqlServer") { }
public virtual DbSet<RestfullApi> restfulapi { get; set; }
}
Code for connecting to the database:
DatabaseContext db = new DatabaseContext();
public string Get()
{
var checkDatabase = db.restfulapi.FirstOrDefault(a => a.UserName != "");
return "Hello World";
}
Error:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source=.Net SqlClient Data Provider
StackTrace:
<Cannot evaluate the exception stack trace>
Inner Exception 1:
Win32Exception: The system cannot find the file specified
User contributions licensed under CC BY-SA 3.0