Error on SQLiteConnection

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
wbschirmacher
Posts: 4
Joined: Wed 22 Apr 2020 13:48

Error on SQLiteConnection

Post by wbschirmacher » Wed 22 Apr 2020 16:46

I am getting an error;

[InvalidCastException: Unable to cast object of type 'Devart.Data.SQLite.SQLiteConnection' to type 'System.Data.SqlClient.SqlConnection'.]

Any idea what might be the cause/solution?

wbschirmacher
Posts: 4
Joined: Wed 22 Apr 2020 13:48

Re: Error on SQLiteConnection

Post by wbschirmacher » Wed 22 Apr 2020 17:38

I solved this partially by replacing the sqlite3.dll with the one that came with the devart connector per the FAQ.

New errors results though, so there is still an issue. Suggestions?

[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
Devart.Data.SQLite.b0.n() +3961
Devart.Data.SQLite.w.a(q A_0, Object A_1, DbConnectionBase A_2) +120
Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, q A_1, DbConnectionBase A_2) +519
Devart.Common.DbConnectionPool.a(DbConnectionBase A_0) +49
Devart.Common.DbConnectionPool.GetObject(DbConnectionBase owningConnection) +1275
Devart.Common.DbConnectionFactory.b(DbConnectionBase A_0) +220
Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection) +391
Devart.Common.DbConnectionBase.Open() +668
Devart.Data.SQLite.SQLiteConnection.Open() +175
Devart.Common.Entity.ez.a(DbConnection A_0) +296
Devart.Data.SQLite.Entity.x.a(SQLiteConnection A_0) +223
Devart.Data.SQLite.Entity.SQLiteEntityProviderServices.GetDbProviderManifestToken(DbConnection baseConnection) +80
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +115

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +375
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +23

[ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.]
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +100
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +88
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +92
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +63
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +225
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +213
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +917
System.Data.Entity.Internal.InternalContext.Initialize() +26
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +20
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +69
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +21
System.Data.Entity.Internal.Linq.InternalSet`1.FindAsync(CancellationToken cancellationToken, Object[] keyValues) +67
System.Data.Entity.DbSet`1.FindAsync(CancellationToken cancellationToken, Object[] keyValues) +46
System.Data.Entity.DbSet`1.FindAsync(Object[] keyValues) +19
Microsoft.AspNet.Identity.EntityFramework.<GetUserAggregateAsync>d__67.MoveNext() +181
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +328
CBL_Tool.Controllers.UserManageController.Index() +173
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +77
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +80
System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +396
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +42
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +651
System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

wbschirmacher
Posts: 4
Joined: Wed 22 Apr 2020 13:48

Re: Error on SQLiteConnection

Post by wbschirmacher » Wed 22 Apr 2020 18:06

Made a few more adjustments and am now back to this. I can login to the application, but as soon as it tries to access data (using MVC setup) I get this:

[InvalidCastException: Unable to cast object of type 'Devart.Data.SQLite.SQLiteConnection' to type 'System.Data.SqlClient.SqlConnection'.]
System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value) +36
System.Data.Entity.Core.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand) +80
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.PrepareEntityCommandBeforeExecution(EntityCommand entityCommand) +198
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +24
System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +1017
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +462
System.Data.Entity.Core.Objects.<>c__DisplayClass41_0.<GetResults>b__0() +227
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +234
System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +357
System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__31_0() +30
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +39
CBL_Tool.Controllers.CategoryController.GetCategoryList() in C:\Users\Walter.Schirmacher\source\repos\CBL\CBL_Tool\CBL_Tool\Controllers\CategoryController.vb:163
CBL_Tool.Controllers.CategoryController.Index() in C:\Users\Walter.Schirmacher\source\repos\CBL\CBL_Tool\CBL_Tool\Controllers\CategoryController.vb:15
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +77
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +80
System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +396
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +42
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +651
System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Error on SQLiteConnection

Post by Shalex » Thu 23 Apr 2020 19:06

BadImageFormatException: An attempt was made to load a program with an incorrect format.
dotConnect for SQLite comes with two versions of sqlite3.dll:
a) 32-bit version
* C:\Program Files (x86)\Devart\dotConnect\SQLite\sqlite3.dll
* C:\Windows\SysWOW64\sqlite3.dll
b) 64-bit version
* C:\Program Files (x86)\Devart\dotConnect\SQLite\x64\sqlite3.dll
* C:\Windows\System32\sqlite3.dll

The bitness (32-bit or 64-bit) of the library must correspond to the bitness of your application. If you need your application to use a specific sqlite3.dll library, you can ensure it in the following way: in a folder with your application create a folder named "x86" (without quotes) or "x64" (without quotes) depending on the bitness of your application. Then place the sqlite3.dll library of the corresponding bitness to this folder. This is the first place where dotConnect for SQLite will search for the library.
Unable to cast object of type 'Devart.Data.SQLite.SQLiteConnection' to type 'System.Data.SqlClient.SqlConnection'.
Registering an Entity Framework provider is different for Entity Framework 6.0 – 6.2 and for Entity Framework 6.3. Refer to https://blog.devart.com/entity-framewor ... pport.html. If this doesn't help, send us a small test project for reproducing the error.

wbschirmacher
Posts: 4
Joined: Wed 22 Apr 2020 13:48

Re: Error on SQLiteConnection

Post by wbschirmacher » Mon 27 Apr 2020 16:49

Badimage format fixed, but still getting [InvalidCastException: Unable to cast object of type 'Devart.Data.SQLite.SQLiteConnection' to type 'System.Data.SqlClient.SqlConnection'.]. Any other ideas?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Error on SQLiteConnection

Post by Shalex » Tue 28 Apr 2020 21:51

We have answered you via email.

Post Reply