Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Integrate NHibernate with SQLCipher #15

Open
Pandurangv opened this issue Sep 13, 2024 · 0 comments
Open

How to Integrate NHibernate with SQLCipher #15

Pandurangv opened this issue Sep 13, 2024 · 0 comments

Comments

@Pandurangv
Copy link

Hi Team,

I am using .Net Framework 4.6.1
Nuget:

  1. Microsoft.Data.Sqlite: 8.0.8.0
  2. zetetic-sqlcipher-windows.4.6.1
  3. NHibernate: 5.3.0.0
  4. NHibernate.Extensions.Sqlite: 2.0.5

But When I am Initializing SQLite NHibernate I am getting below error
Can you please help me on that?

The requested collection ‘DataTypes’ is not defined.Microsoft.Data.Sqlite
Refer Below code.
private void BuildSessionFactory()
{
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
var cfg = new Configuration();
//var licenseCode = "YourLicenseCodeHere";
var _connection = (IDbConnection)new SqliteConnection($"Data Source=test.db;");
_connection.Open();
using (var command = _connection.CreateCommand())
{
command.CommandText = $"PRAGMA cipher_license = '{liscense}';";
command.ExecuteNonQuery();
}

        using (var command = _connection.CreateCommand())
        {
            //PRAGMA key ='{key}';
            command.CommandText = $"PRAGMA key = 'test@2024';";
            command.ExecuteNonQuery();
        }
        using (var command = _connection.CreateCommand())
        {
            command.CommandText = "PRAGMA cipher_page_size = 4096";
            command.ExecuteScalar();
        }

        using (var command = _connection.CreateCommand())
        {
            command.CommandText = "PRAGMA kdf_iter = 256000;";
            command.ExecuteScalar();
        }

        using (var command = _connection.CreateCommand())
        {
            command.CommandText = "PRAGMA cipher_hmac_algorithm = HMAC_SHA512;";
            command.ExecuteScalar();
        }

        using (var command = _connection.CreateCommand())
        {
            command.CommandText = "PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;";
            command.ExecuteScalar();
        }
        _connection.Close();

        cfg.DataBaseIntegration(x => 
        { 
            x.ConnectionString = "Data Source=FIGMD.db;";
            x.Driver<NHibernate.Extensions.Sqlite.SqliteDriver>(); 
            x.Dialect<NHibernate.Dialect.SQLiteDialect>();
            x.ConnectionProvider<NHibernate.Connection.DriverConnectionProvider>(); 
        });

        //NHibernate.Extensions.Sqlite.SqliteDriver sqlitedriver = new NHibernate.Extensions.Sqlite.SqliteDriver();
        
        cfg.AddAssembly(typeof(Student).Assembly);
        
        var factory=cfg.BuildSessionFactory();
        
        Factories.Add(factory);
        //NHibernate.Extensions.Sqlite.SqliteDriver sqliteDriver = new NHibernate.Extensions.Sqlite.SqliteDriver();
        
    }

Exception thrown "var factory=cfg.BuildSessionFactory();" here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant