【发布时间】:2017-07-15 22:10:31
【问题描述】:
我正在尝试使用 Web Api 设置 CouchbaseServer,以便我可以使用 N1QL 在 NOSQL 数据库 Couchbase 上触发基于 SQL 的查询。但是我在获取桶中遇到了一个异常。 这就是我的 CouchBaseConfig 的样子:
public static class CouchbaseConfig
{
private static readonly List<string> TravelSampleIndexNames = new List<string>
{
"def_sourceairport",
"def_airportname",
"def_type",
"def_faa",
"def_icao",
"def_city"
};
public static void Register()
{
var couchbaseServer = ConfigurationManager.AppSettings.Get("CouchbaseServer");
ClusterHelper.Initialize(new ClientConfiguration
{
Servers = new List<Uri> { new Uri(couchbaseServer) }
});
var bucketName = ConfigurationManager.AppSettings.Get("CouchbaseTravelBucket");
var username = ConfigurationManager.AppSettings.Get("CouchbaseUser");
var password = ConfigurationManager.AppSettings.Get("CouchbasePassword");
EnsureIndexes(bucketName, username, password);
}
private static void EnsureIndexes(string bucketName, string username, string password)
{
var bucket = ClusterHelper.GetBucket(bucketName, password);
var bucketManager = bucket.CreateManager(username, password);
var indexes = bucketManager.ListN1qlIndexes();
if (!indexes.Any(index => index.IsPrimary))
{
bucketManager.CreateN1qlPrimaryIndex(true);
}
var missingIndexes = TravelSampleIndexNames.Except(indexes.Where(x => !x.IsPrimary).Select(x => x.Name)).ToList();
if (!missingIndexes.Any())
{
return;
}
foreach (var missingIndex in missingIndexes)
{
var propertyName = missingIndex.Replace("def_", string.Empty);
bucketManager.CreateN1qlIndex(missingIndex, true, propertyName);
}
bucketManager.BuildN1qlDeferredIndexes();
bucketManager.WatchN1qlIndexes(missingIndexes, TimeSpan.FromSeconds(30));
}
public static void CleanUp()
{
ClusterHelper.Close();
}
但是当我运行 web 应用程序时,我收到以下错误:
AuthenticationException: Authentication failed for bucket 'travel-sample']
谁能帮我解决这个问题。 提前致谢!!
【问题讨论】:
-
您是否调试并检查您是否从应用程序配置中获取了正确的用户名和密码值?
-
是的,我已经检查过了。我得到了正确的用户名和密码值。 @ChetanRanpariya
-
您使用的是什么版本的 SDK 和 Couchbase 服务器?