0

I have the following piece of code, which works at a customer, but not on my computer:

var result = await db.Configurations.FirstOrDefaultAsync().ConfigureAwait(false);

db is derived from a System.Data.Entity.DbContext, defined in EntityFramework.6.4.0\lib\net45\EntityFramework.dll.

In the corresponding SQL Server database, there is a table "Configurations" and it contains an entry.

When I launch the line of source code, an Exception gets generated (I hereby show the slightly formatted content of the immediate window while asking ? ex):

? ex
{"An exception occurred while initializing the database. See the InnerException for details."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233087
    HelpLink: null
    InnerException: {"The underlying provider failed on Open."}
    Message: "An exception occurred while initializing the database. See the InnerException for details."
    Source: "EntityFramework"
    StackTrace: "   bij System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)\r\n   bij System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   bij System.Data.Entity.Internal.LazyInternalContext.<>c.<InitializeDatabase>b__58_0(InternalContext c)
   bij System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   bij System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   bij System.Data.Entity.Internal.InternalContext.Initialize()
   bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   bij System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   bij System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   bij System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   bij System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source)
   bij Project.<GetConfigAsync>d__56.MoveNext() in C:\\Source_Code_Directory\\Source_Code_File.cs:regel 2149"
    TargetSite: {Void PerformInitializationAction(System.Action)}

I know this line of code works at customer's system, and I'm working on a restored backup of customer's DB.

What is going wrong and what can I do to fix it (what is the underlying provider)?

Thanks in advance

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • 2
    A couple of things to check first: errors in connection string, access rights or you can try this: https://stackoverflow.com/questions/18271301/entity-framework-the-underlying-provider-failed-on-open , other articles; http://docs.safewhere.com/identify-how-to-solve-the-underlying-provider-failed-on-open-exception/ , https://www.codeproject.com/tips/126919/solution-for-the-underlying-provider-failed-on-ope – Stefan Jan 20 '22 at 08:46

1 Answers1

0

In the meantime the problem is analysed:

I had taken the backup of the customer's DB and restored it on my PC, but the username, as indicated in the connectionstring in source code, was wrong, hence my application could simply not open the database connection, so now the problem comes down on a database user management issue.

Thanks for all the support.

Dominique
  • 16,450
  • 15
  • 56
  • 112