0

I am trying to connect oracle with MVC as below

Config file

<connectionStrings>
 <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=test;Password=123_test;Data Source=local:xxxx/liveprod" />
  </connectionStrings>

User table model

public class sys_users
    {

        [Key]
        public long us_id { get; set; }
        public string us_name { get; set; }

        public string us_pass { get; set; }
}

Db context

public class OracleDBContext : DbContext
    {
        public OracleDBContext()
            : base("name=OracleDbContext")
        {
        }

        public virtual DbSet<sys_users> sys_users { get; set; }
    }

Controller

public ActionResult Login(string Name, string Password)
        {


            var u = db.sys_users.Where(d => d.us_name.Equals(Name) && d.us_pass.Trim().Equals(Password)).FirstOrDefault();
            if (u != null)
            {
                Session["LoggedInAdminUserId"] = u.us_id.ToString();
                Session["LoggedInAdminUsername"] = u.us_name.ToString();
                return RedirectToAction("Login");

            }
            else
            {
                ViewBag.message = "Username or Password is invalid.";
            }

            return View();
        }

But at the line

var u = db.sys_users.Where(d => d.us_name.Equals(Name) && d.us_pass.Trim().Equals(Password)).FirstOrDefault();

I am getting error

ORA-01918: user 'dbo' does not exist

Do I need to do anything else for using oracle tables as model in MVC??

Sachu
  • 7,555
  • 7
  • 55
  • 94
  • Sorry, don't know the client technology you are using. However, the fact that 'dbo' is in lowercase in the error message indicates that your program is passing the username in lower case. A lowercase username in Oracle would be extremely rare. (Honestly, offhand, I don't know if it's even possible. Probably is...) Anyway, try modifying your software to make sure that 'dbo' is passed in as "DBO". – Matthew McPeak Feb 24 '17 at 12:38
  • 1
    Possible duplicate of [Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist](http://stackoverflow.com/questions/27250555/oracle-manageddataaccess-entityframework-ora-01918-user-dbo-does-not-exist) – tpeczek Feb 24 '17 at 12:59

1 Answers1

3
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
   {
   //Configure default schema
   modelBuilder.HasDefaultSchema("STORE");
   }

Entity default schema user is based on Sql (dbo) change the default to anything else but in UPPERCASE

solarsoft0
  • 54
  • 4
  • To improve the quality of your Answer, please explain how your code relates to the other pieces of code supplied and where it should go. Also please explain what you think caused their problem and how your Answer solves this problem. Please remember to include links to any sources that you consider relevant along with the names of their authors. – toonice Apr 29 '17 at 15:56
  • you should place this code where you are creating your app context and the reason why you should try this because the entity framework is not intelligent enough to auto know the database you are working on, UPPERCASE is the key to change his mentality – solarsoft0 Apr 30 '17 at 18:40
  • solved my problem Up voted should be accepted answer – Umair Anwaar May 08 '17 at 11:50