I have the MvcMovie project and have simply aadded a connection string to get to my Sql Server 2008 R2 version for a class called Articles.
I get the error.
The provider did not return a ProviderManifestToken string. 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: Shared Memory Provider, error: 40 – Could not open a
connection to SQL Server)”}
All I have added to the project is
1. a connection string.
<connectionStrings>
<add name="ArticleDB" connectionString="Data Source=Home-PC\SqlServer2008;initial catalog=DairyPump3;integrated security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>
-
A class called Article
public class Article { public int ID { get; set; } public string Menu { get; set; } public string Page { get; set; } //public DateTime ReleaseDate { get; set; } public string Content { get; set; } //public decimal Price { get; set; } } public class ArticleDBContext : DbContext { public ArticleDBContext() : base("ArticleDB") { } public DbSet<Article> Articles { get; set; } } -
A ArticlesController referencing EF etc
I have Sql Server tcp and pipes enabled etc, and I allow remote connections. I have tried with creating the db first and then deleting it – but no difference.
I am not using Code First to my knowledge – at least I do not want to use code first.
The app runs for the MvcMusic side but the config file has no connection string for this – I don’t know where it stores the music data.
I have googled this and many people have encountered the issue, but their solutions do not seem to address this.
Thanks
The constructor overload you’re using is to specify the connection string (“Data source=…”) or the database name at the default SQL instance (e.g. “Initial Catalog=ArticleDb“).
If you name your connection string to
ArticleDBContext(or your context toArticleDB), it should use the connection string you’ve specified, and you don’t need the constructor either.Note: I did a quick confirmation of this using EF CF with migrations. When I used
: base("foo")I saw a new database named foo come up on .\SQLEXPRESS (the default instance used by EF). My observations also seem to be confirmed here.[edit:] Also worth pointing out: when I used the constructor (with
: base("foo)"), it overrode the settings I had in web.config. Probably not something you want to do if you’re deploying to a server where you need to configure the connection string.