【问题标题】:Azure Web App and Azure SQL connectionString errorAzure Web App 和 Azure SQL connectionString 错误
【发布时间】:2020-02-25 00:26:27
【问题描述】:

我已通过门户从我的 Azure SQL 实例中获取连接字符串并将其粘贴到我的 web.config 中。如果我在创建发布配置文件时测试连接字符串,那很好。如果我在 Global.asax 中抛出异常以查看我的连接字符串,如下所示: throw new Exception(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); ,它显示了我的正确答案。但是,我仍然收到此错误:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "Format of the initialization string does not conform to specification starting at index 0.",
  "ExceptionType": "System.ArgumentException",
  "StackTrace": "   at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)\r\n   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)\r\n   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)\r\n   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)\r\n   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)\r\n   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)\r\n   at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)\r\n   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)\r\n   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__18(DbConnection t, DbConnectionPropertyInterceptionContext`1 c)\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext)\r\n   at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)\r\n   at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)\r\n   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()\r\n   at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()\r\n   at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()\r\n   at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)\r\n   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n   at System.Data.Entity.Internal.InternalContext.Initialize()\r\n   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path)\r\n   at System.Data.Entity.Infrastructure.DbQuery`1.Include(String path)\r\n   at ExpressoApi.Controllers.MenusController.GetMenus() in C:\\Users\\david\\Desktop\\ExpressoApi-master\\ExpressoApi\\Controllers\\MenusController.cs:line 17\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
}

我花了几个小时试图解决这个问题,但没有任何进展。

【问题讨论】:

标签: azure azure-sql-database


【解决方案1】:

我发现了问题。只需将连接字符串粘贴到我的 Azure 应用程序的 web.config 中即可。我需要将连接字符串添加到我的 PUBLISHSETTINGS 文件中并重新发布。然后一切正常。

【讨论】:

  • 请将其标记为答案(单击答案旁边的复选标记可将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢
猜你喜欢
  • 2020-09-28
  • 1970-01-01
  • 2015-07-01
  • 1970-01-01
  • 2018-07-09
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多