SessionFactory. Check PotentialReasons collection, and InnerException for more detail+MS SQL Connection
I'm trying to develop my 1st Fluent Nhibernate Application based on this
tutorial , however I'm getting an error on the connection part which gives me this error An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. This my code
public Form1()
{
InitializeComponent();`
sessionFactory = BuildSessionFactory();
}
private static ISessionFactory BuildSessionFactory(){
AutoPersistenceModel model = CreateMappings();
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
.Server("CARDMASTER-PC")
.Database("Fluent")
.Username("sa")
.Password("sa")
.TrustedConnection())
)
.Mappings(m => m
.AutoMappings.Add(model))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private static AutoPersistenceModel CreateMappings()
{
return AutoMap
.Assembly(System.Reflection.Assembly.GetCallingAssembly())
.Where(t => t.Namespace == "SimpleOrmApplication.Model");
}
- Fluent.zip 1.1 MB
Support Staff 2 Posted by James Gregory on 13 Oct, 2010 06:18 AM
Have you checked the InnerException, as the message says to?
3 Posted by Marvin on 13 Oct, 2010 07:50 AM
I tried removing the
.TrustedConnection())
line but it gives me another error which isThere is already an object named 'Product' in the database ...arrrgghhh, but when I removing the line
.ExposeConfiguration(BuildSchema)
, it save 2 records on my store table..actually I'm really lost, what's the functionalities ofnew SchemaExport(config).Create(false, true);
with the method
private static void BuildSchema(Configuration config)
Support Staff 4 Posted by James Gregory on 13 Oct, 2010 08:36 AM
That line creates a database from your mappings. If your database already exists then you don't want to be using SchemaExport.
I don't know where you've copied your code from, but the Fluent NHibernate wiki describes what this does. http://wiki.fluentnhibernate.org/Getting_started#Schema_generation
5 Posted by Marvin on 13 Oct, 2010 08:50 AM
Hi James, Thanks for the helping hand.. Is it possible to delete the scheme manually? can I locate the created scheme in my application?
Based on the link you've given me. I will a replace the dbfile? I'm using sqlserver05
private static void BuildSchema(Configuration config)
Sorry james, I hope there a sample that works on MS Server 05