gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:16:59 25 4
gpt4 key购买 nike

因此,我有一个控制台应用程序,它在本地环境中运行良好,但是当我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com