如何解决 mscorlib.dll Could not extract 'MySqlPassword' from Environment variables..?
how to solve mscorlib.dll Could not extract 'MySqlPassword' from Environment variables..?
这是 NserviseBus 总线的代码,我在 运行 该代码时出错。
错误 "mscorlib.dll Could not extract 'MySqlPassword' from Environment variables" 请帮助我。
谢谢....
using System;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using NServiceBus;
using NServiceBus.Persistence.Sql;
class Program
{
static async Task Main()
{
Console.Title = "Samples.SqlPersistence.EndpointMySql";
#region MySqlConfig
var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
var transport = endpointConfiguration.UseTransport<MsmqTransport>();
transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user=
{username};database=sqlpersistencesample;port=3306;password=
{password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
#endregion
endpointConfiguration.UseTransport<LearningTransport>();
endpointConfiguration.EnableInstallers();
var endpointInstance = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
await endpointInstance.Stop()
.ConfigureAwait(false);
}
}
如何解决 mscorlib.dll 无法从环境变量中提取 'MySqlPassword'..?
请帮帮我..
鉴于该错误消息似乎源自您的代码,即来自
var password = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
我猜要么没有 root
环境变量,要么有一个,但它被设置为空字符串。
此外,鉴于您稍后尝试从同一个环境变量中读取用户名,我认为这里出了点问题。
该代码试图从计算机的环境变量集合中提取用户名和密码。这些设置将根据环境在 运行 中的操作系统而有所不同。
如果Windows中的运行,可以在开始菜单中搜索"Edit the system environment variables"来编辑环境变量。
或者,您可以通过直接在代码中设置变量来跳过环境变量访问:
// ...
var password = "root";
var username = "root";
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
// ...
这是 NserviseBus 总线的代码,我在 运行 该代码时出错。 错误 "mscorlib.dll Could not extract 'MySqlPassword' from Environment variables" 请帮助我。 谢谢....
using System;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using NServiceBus;
using NServiceBus.Persistence.Sql;
class Program
{
static async Task Main()
{
Console.Title = "Samples.SqlPersistence.EndpointMySql";
#region MySqlConfig
var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
var transport = endpointConfiguration.UseTransport<MsmqTransport>();
transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user=
{username};database=sqlpersistencesample;port=3306;password=
{password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
#endregion
endpointConfiguration.UseTransport<LearningTransport>();
endpointConfiguration.EnableInstallers();
var endpointInstance = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
await endpointInstance.Stop()
.ConfigureAwait(false);
}
}
如何解决 mscorlib.dll 无法从环境变量中提取 'MySqlPassword'..? 请帮帮我..
鉴于该错误消息似乎源自您的代码,即来自
var password = Environment.GetEnvironmentVariable("root");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
我猜要么没有 root
环境变量,要么有一个,但它被设置为空字符串。
此外,鉴于您稍后尝试从同一个环境变量中读取用户名,我认为这里出了点问题。
该代码试图从计算机的环境变量集合中提取用户名和密码。这些设置将根据环境在 运行 中的操作系统而有所不同。
如果Windows中的运行,可以在开始菜单中搜索"Edit the system environment variables"来编辑环境变量。
或者,您可以通过直接在代码中设置变量来跳过环境变量访问:
// ...
var password = "root";
var username = "root";
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
// ...