1

I'm following this tutorial : http://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angularjs-free-e-book/

And below is the connection string:

<add name="HomeCinema" connectionString="Data Source=(LocalDb)\v11.0; 
           Initial Catalog=HomeCinema;Integrated Security=SSPI;
           MultipleActiveResultSets=true" 
     providerName="System.Data.SqlClient" />

When I try to run update-database -verbose on the command-line, I'm getting the following error:

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: 26 - Error Locating Server/Instance Specified)

I'm trying to connect to the LocalDB that comes with Visual Studio 2013.

When I look at the output:

Target database is: 'HomeCinema' 
  (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).

This is the constructor:

public HomeCinemaContext()
  : base("HomeCinema")
{
   Database.SetInitializer<HomeCinemaContext>(null);
}

Thank you.

Antoine Pelletier
  • 3,164
  • 3
  • 40
  • 62
Richard77
  • 20,343
  • 46
  • 150
  • 252
  • A local db that comes with visual studio 2013 ? Is it going to actually be useful or it's just for some testing ? – Antoine Pelletier Oct 05 '15 at 18:33
  • Excuse my ignorance. I'm working with VS13. I'm talking about whatever localdb that can be accessed locally. – Richard77 Oct 05 '15 at 18:41
  • if you rigth click on your project, then you can add a database connection (entity or just sql, but entity is much funnier to work with) automaticaly with every necessary information also automaticaly written in your web.config – Antoine Pelletier Oct 05 '15 at 18:44
  • I've right-clicked the connection icon, then created a connection with the following values: `**Server Name: (LocalDb)\v11.0, **Database name: HomeCinema`. I was asked to accept that a database be created because it didn't exist. However, when I run again the `update-database -verbose` command, I get the same error. – Richard77 Oct 05 '15 at 19:12
  • Weird... Visual studio propose to create the data base for you, but then it tells you that it can't find it ? Is there any other command you know other then update-database -verbose that could check if the database really exist ? Also what kind of application are you coding with ? ASP.NET ? MVC ? or just Window Form ? – Antoine Pelletier Oct 05 '15 at 19:32
  • It's a tutorial that can be found here http://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angularjs-free-e-book/ – Richard77 Oct 05 '15 at 19:40
  • Now that i know what your question is really about, i suggest you accept the edit and put a bounty on your question, because i'm certainely not an expert of angular-js and that is what you need... angular-js was important to be mentionned here. – Antoine Pelletier Oct 05 '15 at 19:48
  • Angular is just part of the tutorial. The stage where I am at now, it's just about Entity Framework. – Richard77 Oct 05 '15 at 19:50
  • 1
    Ok but the main difference for me is that there won't be any post_back in your web app, no code behind, no page reload, and for that reason, it will take a relatively good knowlege of both angular and entity because the way you integrate entity mapping and binding in your project is different than in an asp.net application, for exemple. – Antoine Pelletier Oct 05 '15 at 20:00
  • 2
    Did you read the comments below the article? – Gert Arnold Oct 05 '15 at 20:17
  • Yes, that helped as I was able to run successful the command. But they didn't explain why running the command from the data project didn't work. – Richard77 Oct 06 '15 at 15:21

1 Answers1

0

I know this is already old, but what I did to run the command successfully was set HomeCinema.Data as the startup project before running the update-database -verbose command. I think this is so that the command will use the app.config in the HomeCinema.Data project where the connection string is specified.

Referring to one of the comments in the article, I think you can also use the following command. This is assuming that you have HomeCinema.Web as your startup project and that your connection string is set in the Web.config.

update-database -verbose -ProjectName "HomeCinema.Data" -StartupProjectName "HomeCinema.Web" -ConnectionStringName "HomeCinema"