seanthehuman
seanthehuman

Reputation: 21

Cannot Open Database in Visual Studio

I'm going through the ASP.NET "Contoso University" Tutorial found here.

The problem starts when i try to view the database. Following directly from the tutorial, when i go to open the database (SchoolContext), i get this error mesage.

Cannot open database "ContosoUniversity1" requested by the login. The login failed.Login failed for user 'machine\user'.

So on the DB i went to "Modify Connection" and hit OK without changing anything. Then I was able to view the database, tables, views, etc. But there was no info available, so continuing from the tutorial I should have seen the Student entity, but it was not there. And when i run the program and try go to website/students, i get a 404 saying the resource cannot be found.

The connection string i'm using from the tutorial

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

I'm running VS 2013 Community Express. I do not have SQL Server Management Studio installed or any related programs.

I'm on the admin user for the computer.

Is this a problem with my machine or user rights? Do i need to install another program?

Upvotes: 0

Views: 5454

Answers (2)

nik
nik

Reputation: 134

I think you are using the sqlserver express edition which comes with Visual Studio installation. Try adding AttachDBFilename='path of .mdf file of database' also in your connection string.

<connectionStrings>
     <add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\ContosoUniversity1.mdf" providerName="System.Data.SqlClient"/>
</connectionStrings>

Upvotes: 2

Marian Ene
Marian Ene

Reputation: 665

Go to that connection in Server Explorer. Go to Properties and use the connection string from there.

Upvotes: 0

Related Questions