我是一種新的couchbase數據庫,並嘗試編寫代碼以第一次連接到遠程couchbase服務器。我寫了一個控制檯應用程序在C#中,我有一個app.config文件和program.cs文件。如何創建從C#到遠程couchbase數據庫的數據庫連接
我的app.config文件如下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<configSections>
<sectionGroup name="couchbaseClients">
<section name="couchbase"
type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient"/>
</sectionGroup>
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<couchbaseClients>
<couchbase useSsl="false" operationLifeSpan="1000">
<servers>
<add uri="http://xxx.xxx.xxx.xxx:8091/pools"></add>
<add uri="http://xxx.xxx.xxx.xxx:8091/pools"></add>
</servers>
<buckets>
<add name="default" useSsl="false" Username="xxxxxx" password="xxxxx" operationLifespan="2000">
<connectionPool name="custom" maxSize="10" minSize="5" sendTimeout="12000"></connectionPool>
</add>
</buckets>
</couchbase>
</couchbaseClients>
</configuration>
和我的Program.cs文件如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Couchbase;
using Enyim.Caching.Memcached;
using Newtonsoft.Json;
using System.Configuration;
namespace CouchBase_ConnectionTester
{
class Program
{
static void Main(string[] args)
{
using (var cluster = new Cluster("couchbaseClients/couchbase"))
{
using (var bucket = cluster.OpenBucket())
{
}
}
}
}
}
當我嘗試調試代碼,它的代碼行拋出一個錯誤
using (var cluster = new Cluster("couchbaseClients/couchbase"))
錯誤消息是如下
「Couchbase.Cluster」的類型初始值設定項引發異常。
內部異常是如下
從配置節「共同/記錄Common.Logging請幫我在這
無法獲取配置。謝謝您的建議
使用你的答案,我能夠連接到數據庫。唯一的一點是,當我嘗試執行SELECT命令,我得到一個錯誤「 [500]無法執行指定的命令:配置系統初始化失敗」 該錯誤拋出該生產線是 ' CouchbaseCommand cmd = new CouchbaseCommand(「SELECT * FROM KVS」,connection); CouchbaseDataReader rdr = cmd.ExecuteReader();' ExecuteReader是我得到錯誤的行 –
我能夠解決這個錯誤。它來自配置文件。謝謝 –
我很高興你能夠把事情做好!對於將來遇到此錯誤的任何人,您是否可以讓我們知道您在配置文件中所做的更改? –