我目前正在评估ABP 3.9并且租户创建不起作用。 它在执行此代码时失败:
CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));
这是我得到的例外:
Mvc.ExceptionHandling.AbpExceptionFilter - Format of the initialization string does not conform to specification starting at index 0.
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
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 Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
相同的Entity Framework连接与我添加的其他ApplicationService
类一起使用。不知道为什么只有租户创建失败了。我正在扩展示例模板,该模板可在ASP.NET Boilerplate站点上免费获得。
非常感谢您的帮助。问候,Zainu
在Create方法下的TenantAppService类中,注释掉了从输入DTO创建加密连接字符串的代码。添加了一种从配置中读取连接字符串的方法,这在我的情况下起作用,因为我有一个针对所有租户的单个数据库。这个数据库非常小,它只存储有关租户的元数据,而大多数应用程序数据将存储在Azure存储中。
public override async Task<TenantDto> Create(CreateTenantDto input)
{
CheckCreatePermission();
// Create tenant
var tenant = ObjectMapper.Map<Tenant>(input);
//this code is commented since we have single database for all tenants
//tenant.ConnectionString = input.ConnectionString.IsNullOrEmpty()
// ? null
// : SimpleStringCipher.Instance.Encrypt(input.ConnectionString);
//This would read connection string from configuration and pass it to
//connectionstring property of AbpTenant
var configuration =
AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());
tenant.ConnectionString = SimpleStringCipher.Instance.Encrypt(configuration.GetConnectionString(OneCloudConsts.ConnectionStringName));
在Azure中部署代码之前我没有意识到它最终会出现异常“System.ApplicationException:找不到内容根文件夹”。
幸运的是,我在这里讨论https://github.com/aspnetboilerplate/aspnetboilerplate-templates/issues/43和修复是一样的
var startupPath = System.IO.Directory.GetCurrentDirectory(); var configuration = AppConfigurations.Get(startupPath); tenant.ConnectionString = SimpleStringCipher.Instance.Encrypt(configuration.GetConnectionString(OneCloudConsts.ConnectionStringName));