我目前正在评估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
答案 0 :(得分:0)
在TenantAppService类的Create方法下,注释掉了从输入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));
答案 1 :(得分:0)
直到将代码部署到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));