来自 AppFabric Provider 的 Sqlite 连接

Sqlite Connection from AppFabric Provider

我们希望通过使用包括 ReadThruogh-WriteBehind 功能的 Sqlite 在我们的项目中使用 AppFabric 缓存。我成功创建了 Provider 并注册到 GAC。如果我选择 mssql 服务作为数据提供者,一切都会成功。另一方面,如果我选择 sqlite,它会在 GAC 中 Provider 的这一行抛出异常。

SQLiteConnection conn = new SQLiteConnection(@"path");

此异常来自 GAC 中的 Provider,但如果我在服务中编写此行,它会起作用。所以问题是,如果我想从 GAC 连接 sqlite,它会抛出异常:

The cache provider threw an exception during read.

错误信息中没有更多的解释,但是如果尝试从服务连接sqlite,它连接成功。 Sqlite db文件让大家阅读。

似乎存在身份验证问题或类似问题。有什么解决办法?

来自http://msdn.developer-works.com/article/12056989/.ErrorCode%26lt%3BERRCA0025%26gt%3B%3ASubStatus%26lt%3BES0001%26gt%3B

The error code that you are getting translates to DataCacheErrorCode.ReadThroughProviderFailure so this is an error which is happening on the service side and not the client side so client configuration will not help.

In this case you should first check if you have created a Read-Through provider and installed it on the Caching server.

You will get this error if you have created a CUSTOM Read-Through provider (something new in AppFabric 1.1) and an exception is happening in the READ method of that provider. More details about creating the provider at http://msdn.microsoft.com/en-us/library/hh361698(v=azure.10).aspx

If this is a reproducible error, then you should be able to easily Debug the DistributedCacheService.exe process on the Cache server and put a breakpoint on the PUT method and step through it to see if you can find the exception.

The section Testing and debugging the provider out this in detail.

在 GAC 中调试提供程序后,问题是关于 System.Data.SQLite.dll。我也必须将该 dll 注册到 GAC 中,因为它也试图从 gac 中找到该 dll,因此它引发了异常。您需要确保 dll 应该具有强名称。要使其具有强名称,您需要按照以下说明进行操作,

 1. sn -k keyPair.snk  
 2. ildasm System.Data.SQLite.dll
 3. /out:System.Data.SQLite.il  ren System.Data.SQLite.dll
 4. System.Data.SQLite.dll.orig  ilasm System.Data.SQLite.il /dll /key=
    keyPair.snk

如果你的 dll 已经有了强名称(你可以从 dll 属性中检查它)你不需要执行这些步骤。您可以按照以下代码直接将dll注册到GAC中,

gacutil -i System.Data.SQLite.dll 

希望有用。