Entity Framework code-first deployment to company SQL Server issues.
I have an ASP.NET MVVM app that uses EF. It runs perfectly on my development laptop. However when I move the database to the company SQL Server, I'm having issues.
The connection string I’m using in my web.config is
<add name="ApplicationInventoryContext"
connectionString="Data Source=COMPANY_SQLSERVER; Initial Catalog=ApplicationInventory; Integrated Security=True;Connect Timeout=15;"
providerName="System.Data.SqlClient" />
The connection string should be OK as I’m able to connect and query the database using this connection from:
- Visual Studio SQL Server Explorer
- Microsoft SQL Server Management Studio
This is my DbContext:
public class ApplicationInventoryContext:DbContext
{
public DbSet<Application> Applications { get; set; }
public ApplicationInventoryContext() :
base("name=ApplicationInventoryContext")
{
Database.SetInitializer<ApplicationInventoryContext>(null);
}
}
This is the repository where I query the database:
public class DisconnectedRepository
{
public List<Application> GetApplicationsList()
{
using (var context = new ApplicationInventoryContext())
{
return context.Applications.AsNoTracking().ToList();
}
}
.....................
}
When I run the application I got the following error:
Entity Framework Exception SqlException: Cannot open database requested by the login
SqlException: Cannot open database requested by the login .
The login failed for user ' domain\userid’
How could this happens if the error shows the same login I'm using in the two connections above that are Ok?