I am trying to create a database using code-first approach. When I am running the following code I am getting the following exception. How can we overcome this?
Notes:
- I have SQL Server 2008 R2 on my system.
- I am not using any config file. I assumed that it will create database using conventions
- There is no open connection already; I just restarted the system and tested. Still the same issue.
- Runtime version for EntityFramework.dll is v4.0.3xxx
Exception:
The provider did not return a ProviderManifestToken string
Message :
This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.
Inner Exception:
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)
Code:
using System.Data.Entity;
namespace LijosEF
{
public class Dinner
{
public int DinnerID { get; set; }
public int Title { get; set; }
}
public class RSVP
{
public int RSVPID { get; set; }
public int DinnerID { get; set; }
public virtual Dinner Dinner { get; set; }
}
//System.Data.Entity.DbContext is from EntityFramework.dll
public class NerdDinners : System.Data.Entity.DbContext
{
public DbSet<Dinner> Dinners { get; set; }
public DbSet<RSVP> RSVPs { get; set; }
}
}
namespace LijosEF
{
class Program
{
static void Main(string[] args)
{
using (var db = new NerdDinners())
{
var product = new Dinner { DinnerID = 1, Title = 101 };
db.Dinners.Add(product);
int recordsAffected = db.SaveChanges();
}
}
}
}