Reputation: 21
Could not create the driver from
NHibernate.Driver.SqlServerCeDriver, NHibernate, Version=3.3.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
.
inner exeption: The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.
This is the error I get when I try to use fluent nHibernate!
I try the simple examples by the configuration doesn't work well with local database using this dlls.
My code:
private static String ConnectionString = "Data Source = Database1.sdf";
public static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard
.ConnectionString(ConnectionString)
.Driver<NHibernate.Driver.SqlServerCeDriver>()
.Dialect<NHibernate.Dialect.MsSqlCeDialect>())
.Mappings(m => m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()))
.ExposeConfiguration(BuildSchema)
.ExposeConfiguration(x => x.SetProperty("connection.release_mode", "on_close"))
.BuildSessionFactory();
}
private static void BuildSchema(Configuration configuration)
{
SchemaExport schemaExport = new SchemaExport(configuration);
schemaExport.Execute(false, true, false);
}
Thank you! It's very important!
i found that it break in the buildsessionfactory...helpppp!!!!
Upvotes: 1
Views: 4800
Reputation: 2586
If you're coming at this from .net core, and you're getting the error message
The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.
Assuming you've installed NHibernate via NuGet, then you need to ensure the appropriate Sql package is installed. There are a couple of unofficial System.Data.SqlServerCe
out there. In my case I needed System.Data.SqlClient
Upvotes: 7
Reputation: 27944
Are you sure you do have Version=3.3.0.4000 of NHibernate in your bin directory? It looks like you have a different build of NHibernate in your bin directory.
If you sure it is there, check if your references are correct:
Do you have a reference in your project to:
"System.Data.SqlServerCe"
This is located in the following dir:
"C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Desktop\System.Data.SqlServerCe.dll"
Make sure you have:
"Copy Local" to true.
Upvotes: 2