SessionFactory. Check PotentialReasons collection, and InnerException for more detail+MS SQL Connection

Marvin's Avatar

Marvin

13 Oct, 2010 02:14 AM via web

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");
    }
  1. Support Staff 2 Posted by James Gregory on 13 Oct, 2010 06:18 AM

    James Gregory's Avatar

    Have you checked the InnerException, as the message says to?

  2. 3 Posted by Marvin on 13 Oct, 2010 07:50 AM

    Marvin's Avatar

    I tried removing the .TrustedConnection()) line but it gives me another error which is
    There 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 of new SchemaExport(config).Create(false, true);

    with the method

    private static void BuildSchema(Configuration config)

        {
    
            new SchemaExport(config).Create(false, true);
    
    
        }
  3. Support Staff 4 Posted by James Gregory on 13 Oct, 2010 08:36 AM

    James Gregory's Avatar

    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

  4. 5 Posted by Marvin on 13 Oct, 2010 08:50 AM

    Marvin's Avatar

    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)

        {
            if (File.Exists(DbFile))
                File.Delete(DbFile);
            new SchemaExport(config)
                .Create(false, true);
        }

    Sorry james, I hope there a sample that works on MS Server 05

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Five times two is what?