Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Entity Framework Basics Entity Framework and Databases Changing the Database Name

Dmitri Mikhalev
Dmitri Mikhalev
4,462 Points

SystemArgumentException

When trying to create the database with the AppConfig option, I get this error in Program.cs:

"System.ArgumentException HResult=0x80070057 Message=The ADO.NET provider with invariant name 'Sql.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. Source=EntityFramework StackTrace:[...]"

it pops up next to "context" at the bottom, in this part of the code:

context.ComicBooks.Add(new ComicBook()
                {
                    SeriesTitle = "The Amazing Spider-Man",
                    IssueNumber = 1,
                    PublishedOn = DateTime.Today
                });
                context.SaveChanges();

Why is that?

2 Answers

Steven Parker
Steven Parker
231,269 Points

Due to "lazy loading", that's probably the first point in the program where an attempt is made to contact the database.

Since the connection information was just moved to the app.config file in this lesson, I'd look there for a possible typo in the connectionString or providerName.

Dmitri Mikhalev
Dmitri Mikhalev
4,462 Points

I found it later on... thanks for your help!