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>
Henry worked too, no friend
– Carlos Roberto
then do the following: change this: . Connectionstring(c => c.Fromconnectionstringwithkey("Myconnectionstring") , so: . Connectionstring(Properties.settings.Default.Myconnectionstring)
– Henrique Mauri
connection string is not being specified which database will be used.
– Barbetta
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"}
– Carlos Roberto
Barbetta the string is indicating yes to the bank to be used
– Carlos Roberto