Npoco new Database fails with "Value cannot be null"

1.1k Views Asked by At

I am trying to update an MVC project from NPoco 3 to NPoco 5.

I could no longer use:

using var db = new Database("DB");

so I changed it to:

using var db = new Database(ConfigurationManager.ConnectionStrings["DB"].ConnectionString, DatabaseType.SqlServer2012, SqlClientFactory.Instance);

and I even tried:

using var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString); conn.Open();

using var db = new Database(conn);

But no matter what I try, I just get

Value cannot be null

[Exception: No database type found for the type string specified: 'SqlServerDatabaseType'. Make sure the relevant assembly NPoco.SqlServer is referenced.]

NPoco.DynamicDatabaseType.MakeSqlServerType(String type) +194

NPoco.DatabaseType.Resolve(String typeName, String providerName) +298

NPoco.Database..ctor(DbConnection connection, DatabaseType dbType, Nullable`1 isolationLevel, Boolean enableAutoSelect) +111

How do I open a Database connection in version 5 of NPoco? It doesn't seem to work at all.

(I did notice that I am building to .NET Framework 4.6.1, which is also what NPoco 5 says it works on.)

Thanks for any help if anyone else has seen this.

1

There are 1 best solutions below

0
PRMan On

In a change from Version 3 to Version 5, you must also now add the NuGet package NPoco.SqlServer.