none
Connection string setting not found in application config file RRS feed

  • Question

  • Hi,

    I am testing my first Azure Function App, since it needs data from Azure Sql I created a DAL project in the solution (can't add Entity Framework directly in the Function App Project - it gives many errors and seems a known limitation).

    I copied the connection string settings in App.config file of Function App project, but during debug I had the following exception at first db connection:

    System.InvalidOperationException: 'No connection string named 'LPEntities' could be found in the application config file.'

    Is this a known problem or am I doing something wrong?

    Carlo


    • Edited by Azul75 Thursday, December 7, 2017 1:28 PM
    Thursday, December 7, 2017 10:26 AM

Answers

  • Hi,

    here's the full stacktrace:

       at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
       at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
       at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
       at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
       at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__18(DbConnection t, DbConnectionPropertyInterceptionContext`1 c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext)
       at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
       at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       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.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
       at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
       at FunctionApp1.Function1.Run(TimerInfo myTimer, TraceWriter log) in C:\Projects\VSO\FunctionApp1\FunctionApp1\Function1.cs:line 22
       at lambda_method(Closure , Function1 , Object[] )
       at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments)
       at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.<InvokeAsync>d__9.MoveNext()

    I solved this issue adding a partial class with a constructor that accepts the connection string.

    public LPEntities(string connectionString) : base(connectionString)
        {
        }


    • Proposed as answer by Paul Batum Monday, December 11, 2017 6:07 PM
    • Marked as answer by Azul75 Thursday, December 14, 2017 3:24 PM
    Saturday, December 9, 2017 1:49 PM

All replies

  • Searching around I found that connection string has to be specified in the local.settings.json file.

    "ConnectionStrings": {
        "LPEntities": "metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=xxxx.database.windows.net;initial catalog=xxxxx;persist security info=True;user id=xxxxxxxx;password=xxxxxxx;MultipleActiveResultSets=True;App=EntityFramework'"
      }

    But now I get the error:

    System.ArgumentException: 'Keyword not supported: 'metadata'.'


    It seems I'm not the only one having this issue, see this thread (scroll to the bottom)


    • Edited by Azul75 Thursday, December 7, 2017 4:07 PM
    Thursday, December 7, 2017 3:54 PM
  • Can you share the full stacktrace of this exception? It would be good to understand if its coming from the functions layer or from somewhere else.
    Thursday, December 7, 2017 7:59 PM
  • Hi,

    here's the full stacktrace:

       at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
       at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
       at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
       at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
       at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__18(DbConnection t, DbConnectionPropertyInterceptionContext`1 c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext)
       at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
       at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       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.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
       at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
       at FunctionApp1.Function1.Run(TimerInfo myTimer, TraceWriter log) in C:\Projects\VSO\FunctionApp1\FunctionApp1\Function1.cs:line 22
       at lambda_method(Closure , Function1 , Object[] )
       at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments)
       at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.<InvokeAsync>d__9.MoveNext()

    I solved this issue adding a partial class with a constructor that accepts the connection string.

    public LPEntities(string connectionString) : base(connectionString)
        {
        }


    • Proposed as answer by Paul Batum Monday, December 11, 2017 6:07 PM
    • Marked as answer by Azul75 Thursday, December 14, 2017 3:24 PM
    Saturday, December 9, 2017 1:49 PM
  • Glad to hear you got it working. That stack trace makes it pretty clear that the metadata error is coming from the SQL library and not functions. I don't really understand why your fix worked but I'm not a entity framework expert.
    Monday, December 11, 2017 6:07 PM
  • Hi @Azul75

    Sorry to rehash this question.

    I am running into this issue.

    Can you provide me with the shell for the partial class you created?

    Thanks,

    Kaiiak

    Monday, October 15, 2018 6:53 PM