ASP.NET Web Forms Application Using Entity Framework 4.0 Database First
The Contoso University application created by the first of two Web Forms tutorial series at http://asp.net/entity-framework/tutorials/. Continues to be provided alongside version 2 so that it can be used as a starting point for working through the second tutorial series.
Actually I have downloaded your project and I must say this is a very good project specially for beginners (like me).
I was editing the student name and found that I can enter duplicate records and there is no validation available for that. Can you please help me to implement the validation so that I would not be able to enter a duplicate new record and also I should not be able to update any existing record (if same student is already exist).
I put your code on window2008 iis server and it throw the error in web.config for
following errors .
ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +6374602
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +253
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +134
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +440
System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +84
ContosoUniversity.DAL.SchoolEntities..ctor() in C:\VS2010TrainingKit\ASP.NET Web Forms Application Using Entity Framework 4.0 Database First\C#\ContosoUniversity\DAL\SchoolModel.Designer.cs:45
when I and run in local machine it works fine. I need to test my deployment for my project same situation as using your project in our department IIS server. How to resolve the issue in sql connection string in web.config file.
This sounds like a deployment issue rather than an issue with the project code. I'd recommend looking at one of our deployment tutorials, such as
There's an entry in the Troubleshooting tutorial in that series for your error message that might be helpful:
The application uses a LocalDB database that is stored in an .mdf file in the App_Data folder. If you use Visual Studio templates to create MVC or Web Forms projects, by default they specify a LocalDB database for the membership database. It's portable in that it gets copied with the project, but you can't use it when you deploy to production because LocalDB doesn't work with IIS. For an overview of SQL Server editions, see http://msdn.microsoft.com/en-us/library/ms178359.aspx#sqlserver.
I would like to create a project with this template : "asp.net web forms application" (c#).
As known, this template build automatically a local database.
I need to use my personal database (after added to it Membership tables) and from it, add an EF model to the project.
The problem is how to configure the web.config ?
I got this error :
" Unable to find the requested .Net Framework Data Provider. It may not be installed."
just after adding the EF model.
After some search, i noticed that maybe the problem is in the connection string with (system.data.EntityClient and system.data.sqlClient).
My web.config :
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-testapp-20131104233223;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-testapp-20131104233223.mdf" />
<add name="DBSampleEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=DBSample;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<!-- membership -->
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DBSampleEntities" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
How to configure the web.config ?
thanks a lot, albert
The database is portable only in the sense that you can copy the project and it goes with the project because it's a file in the App_Data folder. Most hosting providers don't run SQL Express and you wouldn't typically use SQL Express UserInstance in production. For more information about deploying a web project with a database to a production environment, see
I am starting with VB Web Express 2012 - only worked with VB6 before (& SQL db)
I don't find "ASP.NET Web Application template" - only empty Web site, Web Forms site, same with Razor and Dynamic Entities . . .
I have tried them all and yet I cannot find NavigationMenu even searching through each project?
Also I installed SQLExpress 2005, but when I clicked on the AppData, it returned an error message saying that I needed to make a new connection?
Eventually (!) I removed 2012 and installed 2010 . . .
and it all works perfectly! :)
Thanks so much
A question from tutorial 10 -
Earlier you created a student statistics grid for the About page that showed the number of students for each enrollment date. The code that does this in HomeController.cs uses LINQ:
var data = from student in db.Students
group student by student.EnrollmentDate into dateGroup
select new EnrollmentDateGroup()
EnrollmentDate = dateGroup.Key,
StudentCount = dateGroup.Count()
How does this still work when the Students table is no longer there, having been replaced by the Persons table?
On the value of LINQ, see this MSDN page: http://msdn.microsoft.com/en-us/library/ms178359.aspx#linq
In the earlier tutorial, Code First maps the Student entity to the Student table. In the later tutorial, the Student entity has been changed so that it derives from the Person entity, and from this Code First knows to look in the Person table for student data. Your code can remain the same, but EF looks in different database tables for the data depending on how the entity is configured.