Could not create the driver from NHibernate.Driver.SqlClientDriver,

瀏覽次數:373 次
跳到第一則未讀訊息

ho ihu

未讀,
2022年1月2日 上午11:21:252022/1/2
收件者:nhusers
Dear all,
I am using FluentNhibernate in .Net 6. I want to do crud operations on mssql. 
my code and the error is as below. the sam code is working with framework 4.8 but not working in .net 6

Error: could not create the driver from nhibernate.driver.sqlclientdriver, nhibernate, version=5.3.0.0, culture=neutral, publickeytoken=aa95f207798dfdb4

Code in .net 6 mvc project
    public class DatabaseContext
    {
        private static ISessionFactory session;

        private static ISessionFactory CreateSession()
        {
            const string connectionString = "Data source=HAFIZULLAH-OZGU\\SQLEXPRESS;Database=IHU_AcademicPerformance;Integrated Security=True";

            if (session != null)
            {
                return session;
            }
            var sqlConfiguration = MsSqlConfiguration.MsSql2012.ConnectionString(connectionString);

            return Fluently.Configure()
                .Database(sqlConfiguration)
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<TokenMapping>())
                .ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(false, true, false))
                .BuildSessionFactory();

        }
        public static NHibernate.ISession SessionOpen()
        {
            return CreateSession().OpenSession();
        }
    }

I will be happy for your valuable helpings.

Frédéric Delaporte

未讀,
2022年1月2日 上午11:24:372022/1/2
收件者:nhusers
The exception inner exception details is surely telling what is the trouble. Something like a missing dependency: the default driver for MsSql requires System.Data.SqlClient, which is no more part of the base framework in .Net Core. You have to add a reference on it.

Alexander Zaytsev

未讀,
2022年1月2日 下午6:54:552022/1/2
收件者:nhu...@googlegroups.com
Change

var sqlConfiguration = MsSqlConfiguration.MsSql2012.ConnectionString(connectionString);

To

var sqlConfiguration = MsSqlConfiguration.MsSql2012.Driver<MicrosoftDataSqlClientDriver>().ConnectionString(connectionString);


Best Regards,
Alexander

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/ab81c6e8-07d3-4a20-8de5-2edb0fe5cf19n%40googlegroups.com.

ho ihu

未讀,
2022年1月4日 下午3:20:072022/1/4
收件者:nhusers
Thank you bro, the problem solved with the mentioned driver.


3 Ocak 2022 Pazartesi tarihinde saat 02:54:55 UTC+3 itibarıyla haz...@gmail.com şunları yazdı:
回覆所有人
回覆作者
轉寄
0 則新訊息