c# - 系统参数异常 : Format of the initialization string does not conform to specification starting at index 197?

标签 c# sql-server azure azure-webjobs

因此,我有一个控制台应用程序,它在本地环境中运行良好,但是当我在 Azure 应用程序服务中作为 webjob 运行应用程序时,我收到以下错误:

[06/28/2022 07:59:46 > fa1ef8: INFO]  System.ArgumentException: Format of the initialization string does not conform to specification starting at index 197.
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__18(DbConnection t, DbConnectionPropertyInterceptionContext`1 c)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
[06/28/2022 07:59:46 > fa1ef8: INFO]    at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
[06/28/2022 07:59:46 > fa1ef8: INFO]    at Data.Repository.Repository`1.FirstOrDefault(Expression`1 predicate) in D:\Projects\Repository\Repository.cs:line 594
[06/28/2022 07:59:46 > fa1ef8: INFO]    at ConfigurationService.GetConfigValueByConfigCode(String configType, String configCode, IUnitOfWork uow) in D:\Projects\Configurations\ConfigurationService.cs:line 159
[06/28/2022 07:59:46 > fa1ef8: INFO]    at ArchiveOldSMBFiles.Program.ProcessMethod() in D:\Projects\ArchiveOldSMBFiles\Program.cs:line 104

我做了一些研究,发现问题出在我的数据库连接字符串上。这是我的控制台应用程序的 app.config 中的连接字符串:

<connectionStrings>
        <add name="Entities" connectionString="data source=[Server Name];initial catalog=[Database Name];user id=[Login id];password=[Password];multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

最佳答案

按照azure,标准连接字符串应使用以下给定格式:

Server=tcp:[serverName].database.windows.net;Database=myDataBase;
User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;
Encrypt=True;

所以根据这个你的连接字符串将变成

<connectionStrings>
        <add name="Entities" connectionString="Server=tcp:[serverName].database.windows.net;Database=myDataBase;
User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;
Encrypt=True;" providerName="System.Data.EntityClient" />
</connectionStrings>

查看链接了解更多信息 https://www.connectionstrings.com/azure-sql-database/

关于c# - 系统参数异常 : Format of the initialization string does not conform to specification starting at index 197?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72784286/

相关文章:

c# - RavenDB - 筛选文档并使用索引/查询获取计数

c# - 使用 StructureMap 连接不同的实现

sql-server - 通过SSIS分区导入海量数据

swift - Microsoft Azure移动SDK自定义提供商登录IOS

c# - 关闭“查找和替换”对话框的键盘快捷方式

sql - ColdFusion 表单不向数据库提交数据

sql - TSQL 逗号分隔

amazon-web-services - azure 中是否可以进行跨租户 blob 访问?

c# - 如何在Windows Azure中有效扩展?

c# - 如何调用 ASHX 处理程序并取回结果