使用 maxmind/geoip api 我想出了错误“数据库已关闭”有人知道为什么会这样吗?
我尝试了多种不同的方法(单线和多线解决方案等),但无法弄清楚为什么它不起作用。调试时,我发现正在为 LookupService 代码行读取数据库,因为我可以看到它已经从数据库中检索了国家/地区名称,但是当我尝试使用
string userIpAddress = HttpContext.Current.Request.UserHostAddress;
string geoIpDbPath = "/App_Data/CMSModules/WebAnalytics/MaxMind/";
string geoIpDb = geoIpDbPath + "GeoIP.dat";
LookupService ls = new LookupService(geoIpDb, LookupService.GEOIP_MEMORY_CACHE);
Country c = ls.getCountry(userIpAddress);
这变得非常令人沮丧,因为我可以看到数据库已成功访问并且变量“ls”已被赋予适当的值。
我的方法有什么问题?