0

I'm getting an error while trying to write data to database. I'm using sqlservercompact 4.0 and have installed entityframework.sqlservercompact from nuget package. Here is my installed references enter image description here Edit: as per answer I have changed my provider name but I get new error that saysUnable to find the requested .Net Framework Data Provider. It may not be installed.

 public class PortalContext : DbContext
        {
            public PortalContext() : base("AdminPortal")
            {

            }

            public DbSet<RegisterModel> Users { get; set; } 
        }

name of my database is AdminPortal and table name is Users and in web.config i have

<connectionStrings>
    <add name="AdminPortal" connectionString="Data Source=C:\Users\Biplov\documents\visual studio 2012\Projects\BootstrappingMvc\BootstrappingMvc\App_Data\AdminPortal.sdf" providerName="System.Data.SqlServerCe" />
  </connectionStrings>

in controller I have

[HttpPost]
        public ActionResult Register(RegisterModel user)
        {
            if (ModelState.IsValid )
            {
                var regUser = _db.Users.Create();//error at this line

                regUser.UserName = user.UserName;
                regUser.Password = user.Password;

                _db.Users.Add(regUser);
                _db.SaveChanges();
            }

            return RedirectToAction("Index");
        }
Cybercop
  • 8,475
  • 21
  • 75
  • 135
  • Is that the correct format for a SQL Server Compact database? You don't include any security information, for example. Also, I'm not sure that would be the right provider name. – Ann L. May 31 '13 at 13:39

1 Answers1

0

SQL Server Compact doesn't use the System.Data.SqlClient provider for embedded databases, it used System.Data.SqlServerCe doesn't it?

Quinton Bernhardt
  • 4,773
  • 19
  • 28
  • I changed the providername as you mentioned but now the error says`Unable to find the requested .Net Framework Data Provider. It may not be installed.` So does that mean I haven't installed the database? Cause I have – Cybercop May 31 '13 at 13:50
  • There may be more things wrong here. Checkout http://stackoverflow.com/questions/6947325/connection-string-for-using-sql-server-compact-with-entity-framework here for some guidance. – Quinton Bernhardt May 31 '13 at 14:00