2
I have a personal project on ASP.NET MVC core that supports Docker. I would like to use Nhibernate to persist and retrieve information. In my searches I have not found anyone who uses. I am trying but the following error occurs:
Internal exception:
Sqlexception: A network-Related or instance-specific error occurred while establishing a Connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote Connections. (Preview: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I call the method that updates or generates the database tables in the program.Cs class
public static void Main(string[] args)
{
// Chamando o método que Gera ou atualiza as tabelas do banco de dados
NHibernateHelper.GerarOuAtualizarTabelas();
// Iniciando o Host Web
CreateWebHostBuilder(args).Build().Run();
}
The class NHibernateHelper
:
public class NHibernateHelper
{
private static ISessionFactory fabrica = CriaSessionFactory();
private static ISessionFactory CriaSessionFactory()
{
Configuration cfg = RecuperaConfiguracao();
return cfg.BuildSessionFactory();
}
public static Configuration RecuperaConfiguracao()
{
Configuration cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(Assembly.GetExecutingAssembly());
return cfg;
}
public static void GerarOuAtualizarTabelas()
{
Configuration config = RecuperaConfiguracao();
new SchemaExport(config).Create(true, true);
}
public static ISession AbreSession()
{
return fabrica.OpenSession();
}
}
When switching to run with 'IIS Express', it works normally, I have tried to configure the docker
with the help of a few pages to allow remote connections, but was unsuccessful.
Shows an excerpt of the code where the error is generated.
– Augusto Vasques
I have attached it as a reply. Thank you!
– Henrique.Eichstadt