I'm running the test ASP.NET Core application and have added
Microsoft.EntityFrameworkCore.SqlServer
v2.2.6.
When I try to publish it to IIS, it works and there is no issue.
However, when I run "Start debugging" / Press F5 in Visual 2017 , the code throws an exception:
Instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
Here is my code :
public class mydb: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
string cnn = @"Server=testserver;Database=devdb;User Id=sa;Password=246800;";
Debug.WriteLine("connection string :" + cnn);
optionsBuilder.UseSqlServer(cnn);
}
}
}
public class AccountController : Controller
{
public ActionResult Login(SecurityForm objInput)
{
using (mydb db = new mydb ()) {
var _UserInfo = db.SystemLoginUser.FromSql("exec sp_checklogin @SLOGIN, @SPASSWORD", objInput.username, objInput.inputpasscode).ToList();
} <-- Get server not found here when debug, but work in publish IIS
}
}
and I would like this connection string write in the DbContext
class.
Can anyone help with a solution for this issue?
Thank you