0
我想用Web Api设置CouchbaseServer,以便我可以使用N1QL在NOSQL数据库Couchbase上启动基于SQL的查询。但是我在Getting Bucket中遇到了一个异常。 这是我CouchBaseConfig看起来像:用Web Api验证CouchbaseServer桶“桶名”失败
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服务器? – jeffrymorris