Thursday, August 18, 2022

(Solved) ORA-01031: insufficient privileges error when using Oracle.ManagedDataAccess.EntityFramework

For me this issue occured while migrating .net framework from 4.0 to 4.8. I am using entiry framework to connect to database. As I was connecting to Oracle databse using Oracle.ManagedDataAccess 19.3, I had to upgrade it to latest version Oracle.ManagedDataAccess 21.7 nuget. With that we need to install latest version of Oracle.ManagedDataAccess.EntityFramework also.

Solution for this is, add the below code in DBContext constructor or Application_Start method in Global.asax class.

Reason for this error is, each time DBContext object initializes the Entity Framework was trying to create Oracle table under user that does not have permissions. If you work with existing database disable the initializer like mentioned below. Otherwise each table will be recreated based on C# class definition.

public EmployeeDbContext(): base("name=OracleConnection")
{
    Database.SetInitializer(null);
}

Or,
protected void Application_Start(Object sender, EventArgs e)  
{ 
     Database.SetInitializer(null); 
}

No comments:

Post a Comment