【问题标题】:Authentication failed for bucket "Bucket Name" for CouchbaseServer with Web Api使用 Web Api 对 CouchbaseServer 的存储桶“存储桶名称”进行身份验证失败
【发布时间】: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 服务器?

标签: c# asp.net .net couchbase


【解决方案1】:

我通过更改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);
}

【讨论】:

  • 仅供参考,类似的更改已将 merged 更改为 master 以使其与 Couchbase Server 5.0 兼容。
猜你喜欢
  • 1970-01-01
  • 2023-02-26
  • 2016-05-15
  • 1970-01-01
  • 1970-01-01
  • 2020-09-23
  • 2017-03-25
  • 1970-01-01
  • 2016-11-07
相关资源
最近更新 更多