I am having troubles connecting to SQL database in code first approach. Details are as below
<connectionStrings>
<add name="MydbConn"
connectionString="Data Source=hostname\SQLEXPRESS;Initial Catalog=Test1;UserID=****;Password=****;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Below is the Context Helper
public class DBContext:DbContext
{
public DBContext():base("MydbConn")
{
Database.SetInitializer<DBContext>(new CreateDatabaseIfNotExists<DBContext>());
}
public DbSet<User> User { get; set; }
}
The User Model
public partial class UserChatLog
{
[Key]
public long UserLogId { get; set; }
public string EnterpriseId { get; set; }
}
And Finally DBHelper file
public void Save(User user)
{
DBContext context = new DBContext();
context.User.Add(User);
context.SaveChangesAsync();
}
I am getting the below exception
System.Data.SqlClient.SqlException: '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. The specified LocalDB instance does not exist.