我目前正在评估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()
相同的实体框架连接与我添加的其他ApplicationService
类一起工作。不知道为什么只为租户创建这会失败。我正在扩展示例模板,该模板可以在ASP.NET样板站点上自由使用。
非常感谢您的帮助。问候,Zainu
我没有意识到,直到代码在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.cencrypt(configuration.getConnectionstring(onecloudconsts.connectionstringname));
在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));