Connection Sql Server Fluent NHibernate

0

I'm having trouble setting up connection to Sql Server database I have this connection method but give me this error message when I run the application

public static ISessionFactory CriaConexao()
    {
        try
        {
            if (SessionFactory == null)

                lock (typeof(NHibernateHelper))
                {
                    FluentConfiguration configuration = Fluently.Configure()
                   .Database(MsSqlConfiguration.MsSql2012.ConnectionString(c => c.FromConnectionStringWithKey("MyConnectionString")
                       .ShowSql())
                   .Mappings(c => c.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())).
                   configuration.BuildSessionFactory();
                }

            return SessionFactory;
        }
        catch (Exception ex)
        {
            Log.write(ex.ToString());
            throw;
        }
    }

// {“Valor não pode ser nulo.\r\nNome do parâmetro: Data Source”

AppConfig

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
    </configSections>
  <connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=CARLOS\SQLEXPRESS;Initial Catalog=PAF-ECF;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
    <startup> E:\PROJETO C#\AutomacaoComercial\FrenteCaixa\App.config

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
    
asked by anonymous 21.04.2018 / 22:58

1 answer

0

I've been there too

Try using the following Connection tring:

<add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient" /> 

Any questions go to this link tb: Value can not be null, Parameter name: Data Source

Embrace

    
21.04.2018 / 23:56