I am attempting to do a code first entity framework migration. however I am hitting a connection string error when I attempt to run.
my connection string in my web config file is
<connectionStrings>
<add name="AuthContext" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=owinAuthentication;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
my AuthContext.cs is
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace owinAuthentication
{
public class AuthContext : IdentityDbContext<IdentityUser>
{
public AuthContext()
: base("AuthContext")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<AuthContext, Migrations.Configuration>(ConfigurationManager.ConnectionStrings["AuthContext"].ConnectionString));
}
public DbSet<Client> Clients { get; set; }
public DbSet<RefreshToken> RefreshTokens { get; set; }
}
}
however when I run my app I am receiving.
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=No connection string named 'Data Source=(localdb)\v11.0;Initial Catalog=owinAuthentication;Integrated Security=True' could be found in the application config file.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Infrastructure.DbConnectionInfo.GetConnectionString(AppConfig config)
at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
at System.Data.Entity.Internal.LazyInternalContext.OverrideConnection(IInternalConnection connection)
at System.Data.Entity.Infrastructure.DbContextInfo.ConfigureContext(DbContext context)
at System.Data.Entity.Internal.InternalContext.ApplyContextInfo(DbContextInfo info)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps()
at System.Data.Entity.Database.Exists()
at Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1.IsIdentityV1Schema(DbContext db)
at Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1..ctor(String nameOrConnectionString, Boolean throwIfV1Schema)
at Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext`1..ctor(String nameOrConnectionString)
at owinAuthentication.AuthContext..ctor() in C:\Users\delli\Documents\Visual Studio 2015\Projects\owinAuthentication\owinAuthentication\Models\AuthContext.cs:line 15
InnerException:
looking at other stack overflow answers I tried changing
: base("AuthContext")
to
: base(ConfigurationManager.ConnectionStrings["AuthContext"].ConnectionString));
but still receiving the error.