Jet EntityFramework Provider reporting 'Could not find installable ISAM.' - jet-ef-provider

I am using the JetEntityFrameworkProvider
I am trying to connect to an MS Access file (it has extension .sep but it is indeed an access file). I know JetEntityFrameworkProvider does support DB first but I should be able to manually create the models that I need. (Correct ?)
I am trying to define the connection string and provider in code, but it is not working. When I run it I receive the following error
System.Data.OleDb.OleDbException: 'Could not find installable ISAM.'
Context Class
public class ProjectContext : DbContext
{
private DbConnection con = new JetConnection();
public ProjectContext() : base(new JetConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = 'C:\Test-Project.sep'; providerName = JetEntityFrameworkProvider; User Id = Admin; Jet OLEDB:Database Password = SEEME;""), true)
{
}
public DbSet<Component> Components { get; set; }
}
Entity Class
public class Component
{
[Key]
[Column("Counter")]
public int Id { get; set; }
[Column("Name")]
public string Name { get; set; }
}

Remove providerName = JetEntityFrameworkProvider; from the connection string and try again with just this:
Provider=Microsoft.Jet.OLEDB.4.0; Data Source = 'C:\Test-Project.sep'; User Id = Admin; Jet OLEDB:Database Password = SEEME;"

Related

How sensitive is the Google OpenID Discovery Document to change?

What I am trying to do
I am trying to implement Google OpenID Connect as a means to login to an ASP.NET Core 3.1 website using Google's instructions:
https://developers.google.com/identity/protocols/oauth2/openid-connect#server-flow
Under step 2 of the server flow (Send an authentication request to Google) they recommend retrieving information from their OpenID Discovery Document:
You should retrieve the base URI from the Discovery document using the authorization_endpoint metadata value.
I am currently trying to dynamically deserialize the JSON to a Dictionary<string, string> by using Newtonsoft.Json. But it is giving me some issues (can't seem to deserialize a JSON string array) and I am considering changing my strategy to creating a model for the Discovery Document and using System.Text.Json to deserialize.
Now my question is
How sensitive is Google's Discovery Document to changes that would lead to me having to update my DiscoveryDocument.cs model?
Dilemma
With the Newtonsoft.Json way everything will still work, even if Google decides to remove a random key.
But using the System.Text.Json is the easy way out for me now and removes a dependency on the Newtonsoft library, though I may run into trouble later if Google's Discovery Document changes.
I think you will have a much easier time to use the Microsoft.IdentityModel.Protocols and
Microsoft.IdentityModel.Protocols.OpenIdConnect NuGet packages and use the included parser to do it all for you. The items in the document is pretty standardized but not every provider provides all the items.
public class OpenIDSettings : IOpenIDSettings
{
public string Issuer { get; }
public string jwks_uri { get; }
public string authorization_endpoint { get; }
public string token_endpoint { get; }
public string userinfo_endpoint { get; }
public string end_session_endpoint { get; }
public string check_session_iframe { get; }
public string revocation_endpoint { get; }
public string introspection_endpoint { get; }
public string device_authorization_endpoint { get; }
public ICollection<string> scopes_supported { get; }
public ICollection<string> claims_supported { get; }
public OpenIDSettings(string endpoint)
{
var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
$"{endpoint}/.well-known/openid-configuration",
new OpenIdConnectConfigurationRetriever());
//If you get an exception here, then provider is not running or reachable
var document = configurationManager.GetConfigurationAsync().Result;
//Add the necessary code to populate the properties in this class
Issuer = document.Issuer;
jwks_uri = document.JwksUri;
authorization_endpoint = document.AuthorizationEndpoint;
token_endpoint = document.TokenEndpoint;
userinfo_endpoint = document.UserInfoEndpoint;
end_session_endpoint = document.EndSessionEndpoint;
check_session_iframe = document.CheckSessionIframe;
scopes_supported = document.ScopesSupported;
claims_supported = document.ClaimsSupported;
if (document.AdditionalData.ContainsKey("revocation_endpoint"))
revocation_endpoint = (string)(document.AdditionalData["revocation_endpoint"]);
if (document.AdditionalData.ContainsKey("introspection_endpoint"))
introspection_endpoint = (string)(document.AdditionalData["introspection_endpoint"]);
if (document.AdditionalData.ContainsKey("device_authorization_endpoint"))
device_authorization_endpoint = (string)(document.AdditionalData["device_authorization_endpoint"]);
}
}

ASP.NET Core Entity Framework get related data object

Every time I am trying to get a related object I get error
Object reference not set to an instance of an object
Relevant code:
public class Project
{
public int ProjectId { get; set; }
public string ProjName { get; set; }
public string Description { get; set; }
public virtual List<Developer> MyDevs { get; set; }
}
public class Developer
{
public string Name { get; set; }
public string Skills { get; set; }
public string Email { get; set; }
public virtual Project MyProj { get; set; }
}
//define relationship using fluent api, under AppDbContext
modelBuilder.Entity<Developer>()
.HasOne(d => d.MyProj)
.WithMany(p => p.MyDevs)
.HasForeignKey("ProjectForeignKey");
Add-migration and update-database give no error, but I am not able to find the myDev column in the Project table. I am not able to find the myProj column in the Developer table either, only the foreignkey column.
Running the following seed method adds one project and one developer to the db as expected.
public static void Seed(IApplicationBuilder applicationBuilder)
{
AppDbContext context = applicationBuilder.ApplicationServices.GetRequiredService<AppDbContext>();
Project ProjA = new Project { ProjName = "handyApp", Description = "a dummy Project" };
context.Project.Add(projA);
Developer FirstDev = new Developer { UserName = "John Smith", Skills = "C#", Email = "jsmith#dummymail.com", MyProj = ProjA};
context.Developer.Add(FirstDev);
context.SaveChanges();
}
Then running the following code hits the "Object reference not set to an instance of an object" exception.
Developer Dev = context.Devs.Find(1);
string name = Dev.MyProj.ProjName; //put a break point here, the dubugger tells me Dev.MyProj is null
Please can anyone help to identify what is wrong with my relationship definition.
As # Ivan Stoev pointed out, Lazy loading is not yet supported by EF Core.
https://learn.microsoft.com/en-us/ef/core/querying/related-data

Xamarin Forms - Using SQLite and SQLite Extensions to implement foreign keys

I'm new to Xamarin forms and am up to the point where I now want to be persisting data entered by the user to an Sqlite db. Thankfully, there all plenty of examples to get you started, but thats as far as the help goes... I'm trying to implement a relationship between two entities 'Session' and 'HandHistory'.
A Session can have multiple HandHistories - immediately I saw that some sort of foreign key would be needed here to link these tables/entities together. I read in multiple articles and stack overflow questions that the standard 'sqlite-net-pcl' (by Frank A.Krueger) package offers nothing in terms of foreign keys, and that in order to acquire the functionality I needed to use the SQLiteNetExtensions library. I referred to this article for help:
https://bitbucket.org/twincoders/sqlite-net-extensions/overview
My entities look like this:
Session:
using SQLite;
using SQLiteNetExtensions.Attributes;
namespace PokerSession.Models
{
[Table("Session")]
[AddINotifyPropertyChangedInterface]
public class Session
{
public Session(bool newSession)
{
if (newSession)
{
CurrentlyActive = true;
//HandHistories = new ObservableCollection<HandHistory>();
}
}
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public SessionType SessionType { get; set; } = SessionType.Tournament;
public string Location { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public string GeneralNotes { get; set; }
public int MoneyIn { get; set; }
public int MoneyOut { get; set; }
public int ProfitLoss
{
get
{
var p = MoneyOut - MoneyIn;
if (p < 0)
return 0;
return p;
}
}
/// <summary>
/// If the session has not been completed, set this to true
/// </summary>
public bool CurrentlyActive { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public ObservableCollection<HandHistory> HandHistories { get; set; }
}
}
HandHistory:
using SQLite;
using SQLiteNetExtensions.Attributes;
namespace PokerSession.HandHistories
{
[Table("HandHistory")]
[AddINotifyPropertyChangedInterface]
public class HandHistory
{
public HandHistory()
{
}
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(Session))]
public int SessionId { get; set; }
[ManyToOne]
public Session Session { get; set; }
}
}
I also followed this article for the platform specific implementations for obtaining the SQLiteConnection for the local db:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/databases/
The error I'm getting:
'SQLiteConnection' does not contain a definition for 'UpdateWithChildren' and the best extension method overload 'WriteOperations.UpdateWithChildren(SQLiteConnection, object)' requires a receiver of type 'SQLiteConnection' PokerSession.Android, PokerSession.iOS C:\Poker Notes Live\PokerSession\PokerSession\PokerSession\Services\DataService.cs 46 Active
private SQLiteConnection _database;
public DataService()
{
_database = DependencyService.Get<ISqLite>().GetConnection();
_database.GetTableInfo("HandHistory");
_database.CreateTable<Session>();
_database.CreateTable<HandHistory>();
var session = new Session(false)
{
Location = "Test Location",
Date = new DateTime(2017, 08, 26),
MoneyIn = 35,
MoneyOut = 0,
SessionType = SessionType.Tournament,
GeneralNotes = "blah blah"
};
var hh = new HandHistory();
_database.Insert(session);
_database.Insert(hh);
session.HandHistories = new ObservableCollection<HandHistory> {hh};
_database.UpdateWithChildren(session);
}
So basically it's not allowing me to use the SQLite Extension methods with my SQLiteConnection object (_database) which is confusing as this is the whole point behind the Extension methods? Surely they're made to work with the SQLiteConnection object?? I've also noticed through my playing around that there seems to be two different types of SQLiteConnection... The one I'm currently using is in the 'SQLite' namespace, and another one in the SQLite.Net namespace. I have checked the one in the SQLite.Net namespace and it does seem to like the Extension methods but it requires me to change my platform specific implementation for obtaining the SQLiteConnection, but it would fail at runtime (complaining about my Session entity not having a PK??).
Quite a long winded question I know but it's better to provide more information than not enough, and I'm sure there must be others experiencing similar problems so please comment and offer any help possible, thank you.

Windows Phone sqlite select all

I have a query which simply does, in a table named "CUSTOMER" a select all.
This is my Table:
public class CUSTOMER : Extension.Shared
{
[PrimaryKey, Indexed]
public Guid ID { get; set; }
[Indexed]
public string FULL_NAME { get; set; }
public string PHONE_NO { get; set; }
//public string PIVA_CF { get; set; }
public DateTime? MODIFIED_ON { get; set; }
And this is the query which gives me the problem
public List<CUSTOMER> SelectAll()
{
SQLiteConnection conn = new SQLiteConnection(DatabasePath());
return conn.Query<CUSTOMER>("SELECT * FROM CUSTOMER");
}
Every times i run this operation, the query returns an error from SQLite.cs file:
if (r != SQLite3.Result.OK)
{
throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
}
If the size can be a useful, this table has nearly 50000 records.
I have the same problem in a couple of tables with 100000 or 80000 records.
No problems with other Tables, no problem with other queries.
I can say this because since I thought the table was badly saved, I installed again and again the table, but I noticed that from the same page i can call this query without any problem, for all tables:
public List<CUSTOMER> SelectByFilter(string Filter)
{
SQLiteConnection conn = new SQLiteConnection(DatabasePath());
return conn.Query<CUSTOMER>(string.Format("SELECT * FROM CUSTOMER WHERE FULL_NAME LIKE '{0}%'", Filter));
}
I don't really know where can this error came from. I don't know any size's restriction on Sqlite3. Any help will be appreciated.
This error tells that it cannot find the database at the path given check with isolated storage tool that the database exist in that place also check you are referencing the correct path to database file in your DatabasePAth() method or else try this
public List<CUSTOMER> SelectByFilter(string Filter)
{
string dbpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "yourdatabsefilename.db");
//database is in home directory not in any subfolders. then only this code will work
SQLiteConnection conn = new SQLiteConnection(dbpath);
return conn.Query<CUSTOMER>(string.Format("SELECT * FROM CUSTOMER WHERE FULL_NAME LIKE '{0}%'", Filter));
}

How to get the mysql data in ASP.net MVC3?

I'm trying to get my mysql data in ASP.net MVC3.
The mysql Database Name is supply_db and table name is xcart_orders.
ASP.net code is like below,
(Im just following my book, and just switch to my DB info but it does not work :( )
(I will omit using and namespace)
Web.Config File,
<add name="EFMysqlContext" connectionString="server=XXX.XXX.XXX.XX;User Id=root;pwd=xxx;Persist Security Info=True;database=supply_db"
providerName="Mysql.Data.MySqlClient" />
Abstract/IXcartOrdersRepository.cs
public interface IXcartOrdersRepository
{
IQueryable<XcartOrder> xcart_orders { get; }
}
/Concrete/EFXcartOrderRepository.cs
public class EFXcartOrdersRepository : IXcartOrdersRepository
{
private EFMysqlContext context = new EFMysqlContext();
public IQueryable<XcartOrder> xcart_orders
{
get { return context.xcart_orders; } // I thought the 'xcart_orders' should be match with db table name, isn't it?
}
}
/Entities/XcartOrder.cs
public class XcartOrder
{
[Key]
public int orderid { get; set; }
public string login { get; set; }
public string membership { get; set; }
public decimal subtotal { get; set; }
}
and In my controller,
IXcartOrdersRepository XcartOrdersRepository = new EFXcartOrdersRepository();
int orderCnt = XcartOrdersRepository.xcart_orders.Count();
then error occur, the error message say "{"Table 'supply_db.XcartOrders' doesn't exist"}"
I think I could connect to db, but couldn't get the table.
anybody know which part do I need to change?
Thank you!
can you decorate your Xcartorder class with the Table attribute to explicitly specify the desired name?
[Table("xcart_orders")]
public class XcartOrder
{
...
edit: attribute syntax

Resources