locked
Database Not Being Created RRS feed

  • Question

  • Learning Entity Framework following Julie Lerman's book "Code First".  Using EF 5.0 and VS 2012.  I have both SQL 2008 R2 Express and SQL 2012 Localdb installed.  I've downloaded her first simple example and get the exception below.  Any ideas?

    System.Data.DataException was unhandled
      HResult=-2146233087
      Message=An exception occurred while initializing the database. See the InnerException for details.
      Source=EntityFramework
      StackTrace:
           at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
           at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
           at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
           at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
           at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
           at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
           at System.Data.Entity.Internal.InternalContext.Initialize()
           at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
           at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
           at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
           at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
           at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
           at System.Data.Entity.DbSet`1.Add(TEntity entity)
           at BreakAwayConsole.Program.InsertDestination() in C:\Users\Donald\Desktop\Chapter 2 VB\Data Annotations\BreakAwayConsole\Program.vb:line 21
           at BreakAwayConsole.Program.Main(String[] args) in C:\Users\Donald\Desktop\Chapter 2 VB\Data Annotations\BreakAwayConsole\Program.vb:line 11
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Data.EntityException
           HResult=-2146233087
           Message=The underlying provider failed on Open.
           Source=System.Data.Entity
           StackTrace:
                at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
                at System.Data.EntityClient.EntityConnection.Open()
                at System.Data.Objects.ObjectContext.EnsureConnection()
                at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
                at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
                at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
                at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
                at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
                at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
                at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
                at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
                at System.Data.Entity.Internal.EdmMetadataRepository.QueryForModelHash(Func`2 createContext)
                at System.Data.Entity.Internal.InternalContext.QueryForModelHash()
                at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
                at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata)
                at System.Data.Entity.Database.CompatibleWithModel(Boolean throwIfNoMetadata)
                at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
                at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6()
                at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
           InnerException: System.Data.SqlClient.SqlException
                Class=11
                ErrorCode=-2146232060
                HResult=-2146232060
                LineNumber=65536
                Message=Cannot open database "DataAccess.BreakAwayContext" requested by the login. The login failed.
    Login failed for user 'XPS9000\Donald'.
                Number=4060
                Procedure=""
                Server=.\SQLEXPRESS
                Source=.Net SqlClient Data Provider
                State=1
                StackTrace:
                     at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                     at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                     at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                     at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
                     at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
                     at System.Data.SqlClient.SqlConnection.Open()
                     at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
                InnerException:


    Donald Hofferber

    Friday, September 7, 2012 7:47 PM

Answers

  •   

    In Microsoft SQL Server 20XX there is a folder folder called Configuration Tools. In that folder there is a program called SQL Server Configuration Manager. Execute this program. When the window opens you will see the running instances of SQL Server. Right click on all but one and click on Stop. At this point there is only one instance running and now run your project.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


    Monday, September 10, 2012 12:35 PM

All replies

  • Hi Donald;

    The error states that "The login failed" for the user 'XPS9000\Donald'.", did you supply the correct password?

    If you tell me which of the same programs from her download I will look to see if I had to do anything different when I read her book.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, September 7, 2012 8:07 PM
  • With this first example you just let the framework do its thing with all defaults.  No where to add a password in the example.  XPS9000\Donald is password protected so that may be the problem.

    The eample is from "Code First Edition Chapter 2" and can be found at: http://thedatafarm.com/LearnEntityFramework/downloads/


    Donald Hofferber

    Friday, September 7, 2012 8:14 PM
  • Correction.  XPS9000\Donald uses Windows Authentication and does not require a password.

    Donald Hofferber

    Friday, September 7, 2012 8:26 PM
  • Hi Donald;

    I just compiled and ran the project in chapter 2, BAGA_FluentAPI, with out any issues.

    Did you make any changes to the code before running?

    Try running Visual Studio as Admin and if that did not work then run the program from the bin/debug directory  BreakAwayConsole.exe as Admin.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, September 7, 2012 8:48 PM
  • No changes but I had to add the NuGet package for Entity Framework.  VS 2010 and VS 2012 both crash while loading the package but it shows then as installed.  Nowever, I have to add the references by hand to each project.  Perhaps the NuGet package loading improperly is the answer.  Not sure how to fix that???

    Donald Hofferber

    Friday, September 7, 2012 9:50 PM
  • I was using VB.Net example with EF 5.0 so I downloaded C# example using EF 4.2.  Run with no changes and get same error.  Has to be something outside like folder permissions or IIS or SQL???

    Donald Hofferber

    Friday, September 7, 2012 10:03 PM
  • I would download again the project files and just try without reloading NetGet packages because everything that is needed is already in the projects. 

    Console app should have a reference to both DataAccess and Model
    DataAccess  should have a reference to Model only
    Model should NOT have any references to the other projects.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, September 7, 2012 10:04 PM
  •  

    More likely SQL issue because the error states that the application was communicating with SQL but was denied access due to log in failure. 


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, September 7, 2012 10:12 PM
  • Tried this and still the error. 

    Donald Hofferber


    This was reply to previous message.  Not last message.
    • Edited by DDHSolutions Saturday, September 8, 2012 12:21 AM
    Friday, September 7, 2012 11:34 PM
  •  

    If you can zip the project that is giving you issues I will verify on my system that it is working fine or not. If you can place it on you SkyDirive and post the link here I will try it out.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, September 8, 2012 2:31 AM
  • I've found that Entity Framework is not installing completely.  The installation always crashes and restarts Visual Studio.  The package shows as installed but the installation did not complete.  Windows 7/64, VS 2012 Pro, SQL Express 2012 & Localdb.  I've tried a bunch of uninstall/re-installs but nothing helps.  Ideas?

    Donald Hofferber

    Sunday, September 9, 2012 5:32 PM
  • Update.  I tested it on Visual Studio 2010 and it also crashes and fails to install the framework.

    Donald Hofferber


    Sunday, September 9, 2012 5:43 PM
  •   The downloads from the book already have the EF installed into the project. Did you try it without updating EF?


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, September 9, 2012 6:14 PM
  • Just tried this and still failed.  It has to be an SQL issue since I have SQL Express 2008R2, SQL Express 2012 and SQL Express 2012 Localdb installed.  It either can't decide which to use or doesn't have access to Master???????? 

    Donald Hofferber

    Sunday, September 9, 2012 8:48 PM
  •   

    In Microsoft SQL Server 20XX there is a folder folder called Configuration Tools. In that folder there is a program called SQL Server Configuration Manager. Execute this program. When the window opens you will see the running instances of SQL Server. Right click on all but one and click on Stop. At this point there is only one instance running and now run your project.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


    Monday, September 10, 2012 12:35 PM
  • This isn't quite the answer but very close.  I only had one instance (default) of SQL Express running and restarted that and still had the failure.  Like you, I still felt that there was a conflict between SQL installations so I removed the Localdb version of SQL 2012 and the program ran fine.  Now I need to figure out why the EF installer can't handle multiple versions of SQL side by side.  Will report back when/if I find something.  Thanks for sticking with this.  It was a tough one.

    Donald Hofferber

    Monday, September 10, 2012 7:00 PM
  •   

    Glad to hear that you have corrected your issue. Have a great day.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, September 11, 2012 4:11 AM