Advantage Database Server 11 connection string for Code First - advantage-database-server

I am having problem with ADS11 connection string for code first,
I've tried many way but I couldn't make it.
Anybody know, please advice me.
Here is my working environment.
Server : Advantage Database Server 11
Path : \ADS_DB:6262\DB\DBB.ADD (Port : 6262)
Test Access Table : WEBORDERLN (ADT Type)
PK : PK (Char (36))
I downloaded Advantage.Data.Provider v11 and Advantage.Data.Entity v11.
And add to reference.
Web.config
<connectionStrings>
<add name="Ads_Context" connectionString="Data Source=\\ADS_DB:6262\DB\DBB.ADD;User ID=xxx;Password=xxx;ServerType=REMOTE;" providerName="Advantage.Data.Provider" />
</connectionStrings>
Controller,
public class Ads_Context : DbContext
{
public Ads_Context(): base("name=Ads_Context")
{
}
public DbSet<WebOrderLN> webOrderLns { get; set; }
}
public class HomeController : Controller
{
//
// GET: /Home/
public string Index()
{
var context = new Ads_Context().webOrderLns.ToList(); // Source error point to here
return "A";
}
}
[Table("WEBORDERLN")]
public class WebOrderLN
{
[Key]
public string PK {get; set;}
public string FK { get; set; }
public string pickno { get; set; }
}
When I run above code, I got an error message,
Server Error in '/' Application.
Error 7200: AQE Error: State = HY000; NativeError = 5174; [iAnywhere Solutions][Advantage SQL][ASA] Error 5174: Advantage failed to open the specified link. dbo: Error 7041: File not found. Verify the specified path and file name is correct. Table name: WEBORDERLN AdsCommand query execution failed.
Anybody know, what I am doing wrong?

Try adding the schema name of ::this to your tables in code.
[Table( "WEBORDERLN", Schema = "::this" )]
public class WebOrderLN
{
[Key]
public string PK {get; set;}
public string FK { get; set; }
public string pickno { get; set; }
}
See this Knowledge Base Item
http://devzone.advantagedatabase.com/dz/content.aspx?Key=17&RefNo=120423-2510

Related

Unable to create view for an action unable to retrieve metadata for

I have looked for couple of solutions online such as changing the name of the provider in config file. But the problem rely on when I am creating a new view for the an action I keep getting the following error:
There was an error running the selected code generator: 'Unable to
retrieve metadata for' Models.ApplyForJob'.'
Model:
public class ApplyForJob
{
public int Id {get;set;}
public string Message {get;set;}
public DateTime ApplyDate {get;set;}
public int JobId { get; set; }
public string UserId { get; set; }
public virtual Jobs job {get;set;}
public virtual ApplicationUser user {get;set;}
}
Controller
public ActionResult GetJobByUser()
{
var UserId = User.Identity.GetUserId();
var Jobs = db.ApplyForJobs.Where(a => a.UserId == UserId).ToList();
return View(Jobs);
}
What I did to solve is to leave the "Data context class" field blank.

.Net MVC Repository Pattern with EF throwing Error (Local threw an exception of type 'System.InvalidOperationException'

I am getting below error from objContext.warrantys property of entity framework.
Error Message:A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'System.Data.OleDb.OleDbConnection'. The store provider might not be functioning correctly.
Local 'objContext.warrantys.Local' threw an exception of type 'System.InvalidOperationException' System.Collections.ObjectModel.ObservableCollection<DSGWarrantyServiceRep.Core.warranty> {System.InvalidOperationException}
In Web.config,
public class warranty
{
public int WarrantyId
{
get;
set;
}
[Required(ErrorMessage =" Please provide Warrranty Name")]
[MinLength(4)]
public string WarrantyName
{
get;
set;
}
[Required(ErrorMessage = " Please provide Warrranty Period")]
public string WarrantyPeriod
{
get;
set;
}
[Required(ErrorMessage = " Please provide UPC Nbr")]
public string UpcNbr
{
get;
set;
}
public warranty()
{
}
}
Now, I am going to add dbcontext class.
public class WarrantyContext:DbContext
{
public WarrantyContext() : base("name=warrantyConnectionString")
{
}
public DbSet<warranty> warrantys { get; set; }
}
Now From My warranty service class implemented here
public class WarrantyService : IWarrantyService
{
WarrantyContext objContext = new WarrantyContext();
public void AddWarranty(warranty ws)
{
objContext.warrantys.Add(ws);
objContext.SaveChanges();
}
public IEnumerable<warranty> GetAllWarranty()
{
**return objContext.warrantys;**
}
}
It looks as if you need to check your connection string in the web.config (web app) or app.config (other). Feel free to post it here too. You seem to be using the OLEDB, and you should be using native SqlClient instead.
You should have something that looks like this (local db in this case, but could be SQL for you), for example:
<connectionStrings>
<add name="warrantyConnectionString" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-TestApp1-20170112094217.mdf;Initial Catalog=aspnet-TestApp1-20170112094217;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

Code first initial create with MVC identity 2.0

I'm creating initial migration using
Add-Migration InitialCreate
But then when I'm updating my database tables from IdentityDbContext are not created so I get exceptions.
So how do I create migration for AspNetUser tables from IdentityDbContext?
Regards teamol
You can add custom fields to your AspNetUser table in your IdentityModels.cs file.
First add your custom values ito ApplicationUser class in IdentityModels:
namespace YourProjectName.Models
{
public class ApplicationUser : IdentityUser
{
public string Email { get; set; }
public string NameSurname { get; set; }
public string ProfilePhotoRoute { get; set; }
public string Title { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
After that, enter "Add-Migration NewMigration" command in package manager console.
Finally, enter "Update-Database" command in package manager console.
If your connection string -which is stated in web.config- is true, you can update succesfully your database with this way.

Error: The entity type ApplicationUser is not part of the model for the current context [duplicate]

I'm migrating from Identity 1.0.0 to Identity 2.0.1 following this article
and the migrations code generated is nothing about the new IdentityUser. It doesn't add the new columns.
So I made a new project and tried again but the migrations codes is empty.
To fix that problem, I did the edits directly in SQL Server and imported my database again in my solution.
Now my AspNetUser is exactly the same as my IdentityUser as you can see
IdentityUser
public virtual int AccessFailedCount { get; set; }
public virtual ICollection<TClaim> Claims { get; }
public virtual string Email { get; set; }
public virtual bool EmailConfirmed { get; set; }
public virtual TKey Id { get; set; }
public virtual bool LockoutEnabled { get; set; }
public virtual DateTime? LockoutEndDateUtc { get; set; }
public virtual ICollection<TLogin> Logins { get; }
public virtual string PasswordHash { get; set; }
public virtual string PhoneNumber { get; set; }
public virtual bool PhoneNumberConfirmed { get; set; }
public virtual ICollection<TRole> Roles { get; }
public virtual string SecurityStamp { get; set; }
public virtual bool TwoFactorEnabled { get; set; }
public virtual string UserName { get; set; }
IdentityUser.cs
public class ApplicationUser : IdentityUser
{
public bool Has_accepted_policy { get; set; }
public int user_type_id { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
AspNetUser
public string Id { get; set; }
[Required]
[StringLength(256)]
public string UserName { get; set; }
public string PasswordHash { get; set; }
public string SecurityStamp { get; set; }
[StringLength(256)]
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public bool Is_Active { get; set; }
[Required]
[StringLength(128)]
public string Discriminator { get; set; }
public int? user_type_id { get; set; }
public bool Has_accepted_policy { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public bool TwoFactorEnabled { get; set; }
public DateTime? LockoutEndDateUtc { get; set; }
public bool LockoutEnabled { get; set; }
public int AccessFailedCount { get; set; }
... other virtual properties
and when I try to register a user I have the following exception
The entity type ApplicationUser is not part of the model for the current context
at this line
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
My startup.Auth.cs
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());
And in my AccountController I declare my UserManager like this
public AccountController()
: this(Startup.UserManagerFactory(), Startup.OAuthOptions.AccessTokenFormat)
{
}
public AccountController(UserManager<ApplicationUser> userManager,
ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
UserManager = userManager;
AccessTokenFormat = accessTokenFormat;
}
public UserManager<ApplicationUser> UserManager { get; private set; }
I haven't changed anything except the new properties in the AspNetUser class and it used to work well before the migration.
There's a similar issue on CodePlex marked as fixed but they don't give the solution
Does anyone know how to fix this?
EDIT
To be sure I didn't do any mistakes when I edited my SQL database. I created another project and generated an Identity database and I changed the connection string for that database and I still have the same error.
SOLUTION
When I have edited my database I haven't noticed that in Identity 2.0.0 they changed the User_Id for UserId in AspUserClaims table. After doing that I had the same error but then I did what tschmit007 said about adding the ApplicationDbContext to the UserStore constructor and now it works.
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
I was having this same problem. I’m doing database first development with an EDMX file. If you are using the connection string generated when adding the EDMX file in :base(“EDMXConnString”) you will most likely have this problem.
I fixed this by creating a standard connection string that pointed to the database where the ASP.NET Identity tables are.
<add name="MyConnString" connectionString="Data Source=server; Initial Catalog=db_name; User ID=user_id; Password=password; Connect Timeout=60;" providerName="System.Data.SqlClient" />
And then used that connection string in :base, and it worked!
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("MyConnString")
{
}
}
for me it seems to miss a context instanciation:
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());
should be
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
My problem was I tried to use generated ADO.NET connection string for both generated and authentication context ApplicationDbContext. I fixed it by using a separate connection string for authentication. Also pay attention to the provider - for authentication context it has to be System.Data.SqlClient:
<add name="DefaultConnection" connectionString="Server=qadb.myserver.com;Database=mydb;User Id=myuser;Password=mypass;" providerName="System.Data.SqlClient" />
If you are using code first, check your connection string to ensure providerName is 'SqlClient' as in providerName="System.Data.SqlClient
If you are using database first, check your connection string to ensure providerName is 'EntityClient' as in providerName="System.Data.EntityClient
Same problem to me, it solved by this code:
public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
{
Database.Connection.ConnectionString = #"data source=...;initial catalog=...;user id=...;password=...;multipleactiveresultsets=True;application name=EntityFramework";
}
I also received this error message, but the cause and solution were different. In my case, I had introduced a new Id property of type Guid in my ApplicationUser class. Perfectly valid C# syntax, but it apparently created massive confusion for the Identity or EntityFramework core that relies on reflection to find stuff.
Removing the new Id property in my ApplicationUser class resolved this error.
I ran into this issue and it was an object name conflict. The IdentityConfig.cs was using ApplicationUser, but it was using the auto-generated IdentityModels.ApplicationUser instead of my own context's DataAccess.ApplicationUser. Made perfect sense once I found it. So, I deleted the auto-generated IdentityModels.cs from the base WebAPI template - not using that anymore anyway - then I added the using statement in IdentityConfig.cs to my own DataAccess namespace and voila, proper mapping. If you forget the template built a lot of this for you, you'll run into the issue:
public class ApplicationUserManager : UserManager<ApplicationUser> // the name conflict
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
My issue was that I had created a new DbContext, but it wasn't inheriting from IdentityDbContext.
An easy fix...
public partial class GoldfishDbContext : IdentityDbContext<ApplicationUser>
{
....
}
I am sure not why this happens, my solution works perfectly fine, tested everything before I sleep. After 12 hours, I checked it again and run and this was exactly the same error. I tried almost all solutions here in SO but none of them works.
I am implementing a database approach here. Then suddenly there was this
DefaultConnection
on my web.config that Visual Studio generated when I first created the solution. So I've used it instead of the connection string that was generated by my EDMX file and suddenly it works!
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
This was my connection string that works:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-System.WEB-20180718085411.mdf;Initial Catalog=aspnet-System.WEB-20180718085411;Integrated Security=True" providerName="System.Data.SqlClient" />
Originally I am using this that was generated by my EDMX file but suddenly the website doesn't work although it works before. I didn't change anything and all code was in TFS, so I am 100% sure it works and I did a full restore and get the latest version:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-System.WEB-20180718085411.mdf;Initial Catalog=aspnet-System.WEB-20180718085411;Integrated Security=True" providerName="System.Data.SqlClient" />
This happened to me because I was trying to wire up ApplicationUserManager and some other related dependencies using my dependency injection container. In some cases, the container resolved ApplicationDbContext in other cases the built-in injector in Owin would resolve it.
The easiest way to make sure this doesn't happen is to not try to wire up any of the Auth stuff using your DI container of choice unless you really know what youre doing with DI...otherwise just let Owin resolve it using the built in injector.
In other words, remove anything like:
builder.RegisterType<ApplicationUserManager>().InstancePerRequest();
And just let Owin resolve it the way it was built in:
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}

create new controller - error running selected code generator

I am using Visual Studio Express 2013 for Web (specifically version 12.0.21005.1 REL). This is my first project using VS2013, I've been using VS2012 up until this point.
I am attempting to create a new controller in my asp.net MVC application. I am using Entity Framework 5 with code first (.NET 4.5). I want Visual Studio to create the template for me (you know, a controller with views to read/write/delete etc, rather than write the code myself from scratch).
However, every time I try to create the controller I get the following error message:
Is there some sort of bug in VS 2013? I can't figure out what this means, and restarting VS2013 does not help.
Here are the gory details.... actually it is all very simple since this is a new project with very little code written so far.
My model:
namespace ProfessionalSite.Models
{
public class EntityModels
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
public class Enrollment
{
public int ID { get; set; }
public string EnrollmentName { get; set; }
public string Credits { get; set; }
}
// Create the class that inherits from DbContext
// The name of this class is also used as the connection string in web.config
public class EFDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
}
}
}
And in my web.config file I have the following
<add name="EFDbContext"
connectionString="Data Source=JONSNA\SQLEXP2012WT;Initial Catalog=ProfessionalSiteDb; Integrated Security=True; MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
within the tags.
Now time to create a controller. I right click on Controllers in the Solution Explorer, and choose to Add a new Controller.
And then
And when I click Add I get
I cant figure out how to get rid of this error. I guess as a workaround I can just type the code myself, but I'd like to know if this is a bug or something I have done wrong. In VS2012 this just worked...
I'd appreciate any help or pointers. Thanks.
You don't need the EntityModels class, See below:
namespace ProfessionalSite.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
public class Enrollment
{
public int ID { get; set; }
public string EnrollmentName { get; set; }
public string Credits { get; set; }
}
// Create the class that inherits from DbContext
// The name of this class is also used as the connection string in web.config
public class EFDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
}
}
Then when you create a controller, just select the Student or Enrollment for the Model class.

Resources