我正在尝试用Web设置CouchbaseServer,这样我就可以使用N1QL在NOSQL数据库Couchbase上启动基于SQL的查询。但是我在获取Bucket时遇到了一个异常。这是我的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']

有人能帮我解决这个问题吗?提前感谢!!
发布于 2018-02-20 22:47:06
通过如下所示更改CouchbaseConfig.Register,我克服了这个错误:
public static void Register()
{
var couchbaseServer = ConfigurationManager.AppSettings.Get("CouchbaseServer");
var username = ConfigurationManager.AppSettings.Get("CouchbaseUser");
var password = ConfigurationManager.AppSettings.Get("CouchbasePassword");
ClusterHelper.Initialize(
new ClientConfiguration
{
Servers = new List<Uri> { new Uri(couchbaseServer) },
},
new PasswordAuthenticator(username, password));
var bucketName = ConfigurationManager.AppSettings.Get("CouchbaseTravelBucket");
EnsureIndexes(bucketName, username, password);
}https://stackoverflow.com/questions/45123148
复制相似问题