Sql Server Fluent Nhibernate Connection

Asked

Viewed 510 times

0

I’m having trouble configuring connection to Sql Server database I have this connection method but give me this error message when running 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>

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 doubt search this link tb: Value cannot be null, Parameter name: Data Source

Hug

  • Henry worked too, no friend

  • then do the following: change this: . Connectionstring(c => c.Fromconnectionstringwithkey("Myconnectionstring") , so: . Connectionstring(Properties.settings.Default.Myconnectionstring)

  • connection string is not being specified which database will be used.

  • hello the result (Properties.settings.Default.Myconnectionstring) error message {"An invalid or incomplete Configuration was used while Creating a Sessionfactory. Check Potentialreasons Collection, and Innerexception for more Detail. r n r n"}

  • Barbetta the string is indicating yes to the bank to be used

Browser other questions tagged

You are not signed in. Login or sign up in order to post.