2016-07-12 27 views
0

我正在与Cassandra一起工作,并尝试连接Cassandra中的数据库,但它收到错误,如“System.FormatException' occurred in Cassandra.dll but was not handled in user code”和附加信息为Contact Points value are missing in the connection string。你可以看看我的连接代码如下使用Cassandra连接字符串中缺少联系点值

的HomeController

public class HomeController : Controller 
    { 
     //CqlConnection cqlConnection = new CqlConnection(); 
     private string conString = ConfigurationManager.ConnectionStrings["CassandraConnString"].ToString(); 

     // GET: Home 
     public ActionResult Index() 
     { 
      using (CqlConnection cqlConnection = new CqlConnection(conString)) 
      {     
       cqlConnection.Open(); 
      } 


      return View(); 
     } 
    } 

WebConfig

<connectionStrings> 
    <add name="CassandraConnString" connectionString="Database=StudentMaster;Port=9042;Server=127.0.0.1;"/> 
    </connectionStrings> 

可否请你指教解决连接问题,并请让我知道你的想法。

+0

我有与此相关的另一个问题。我如何从Cassandra检索数据?有没有CRUD功能的数据访问库? –

回答

1

连接字符串应类似于此:

Contact Points=127.0.0.1;Default Keyspace=StudentMaster 

你可以在这里查看可用的连接字符串元素: https://github.com/datastax/csharp-driver/blob/master/src/Cassandra/CassandraConnectionStringBuilder.cs

+0

我试过类似的方法不同但它不起作用 –

+0

你的错误信息和新的连接字符串是什么?您的原始错误消息“连接字符串中缺少联系点值”应使用建议的连接字符串修复。 – medvekoma

+0

我已解决连接字符串问题,现在它工作正常 –