Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Apache
Hello,
 
I would like to use Apache Cassandra database with help of cassandra-sharp to use it in C#. However, I have some problem with correctly referencing everything to ensure I can use Cassandra there.
 
I have found this article (http://www.semoru.com/2012/07/27/how-to-connect-cassandra-and-net-framework-3-5/#comment-2766). I have converted the code from VB to C# and it looks like everything is correctly converted, except three lines.
 
using CassandraSharp.MadeSimple;
using Apache.Cassandra;
 
It cannot find MadeSimple and Apache. (Other using statements are OK after adding reference to cassandra library).
 
CqlResult res = cluster.ExecuteCql(queryString);
CqlResults and ExecuteCql cannot be found.
 
Could you give me some guidelines where it may result from?
The rest of code is OK.
 
Thanks in advance!
 
PS I have posted comment to that article but as last comment was from February, it may be simply forgotten by tutorial's creator or it may require some time to get any response.
 
The full code is like this:
 
//using System;
//using System.Collections.Generic;
using System.Linq;
//using System.Text;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using CassandraSharp;
using System.Text;
using CassandraSharp.Config;
using CassandraSharp.MadeSimple;
using Apache.Cassandra;
 
namespace CassandraSharpTest
{
    class Program
    {
        //static void Main(string[] args)
        //{
        //}

        public static void Main()
        {
            // Loading Cassandra configuration...
            XmlConfigurator.Configure();
            ICluster cluster = ClusterManager.GetCluster("TestCassandra");
 
            // Define your query
            string queryString = "select * from table";
 
            //Execute your query in Cassandra
            CqlResult res = cluster.ExecuteCql(queryString);
 
            // Connection release
            ClusterManager.Shutdown();
 
            // Get results. In this example integer, date and double types
            //
            //getId(res.Rows.ElementAt(i).Columns.ElementAt(0).Value
            //getDate(res.Rows.ElementAt(i).Columns.ElementAt(j).Name)
            //getDouble(res.Rows.ElementAt(i).Columns.ElementAt(j).Value))  

        }
 
        public int getId(byte[] value)
        {
            byte[] buffer = new byte[value.Length];
            value.CopyTo(buffer, 0);
            Array.Reverse(buffer);
            int result = BitConverter.ToInt32(buffer, 0);
            return result;
        }
 
        public DateTime getDate(byte[] value)
        {
            byte[] buffer = new byte[value.Length];
            value.CopyTo(buffer, 0);
            Array.Reverse(buffer);
            long ticks = BitConverter.ToInt64(buffer, 0);
            System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
 
            dateTime = dateTime.AddMilliseconds(ticks);
            return dateTime;
        }
 
        public double getDouble(byte[] value)
        {
            byte[] buffer = new byte[value.Length];
            value.CopyTo(buffer, 0);
            Array.Reverse(buffer);
            double result = BitConverter.ToDouble(buffer, 0);
            return result;
        }
    }
}
Posted 18-Apr-13 10:38am
Comments
Sergey Alexandrovich Kryukov at 18-Apr-13 15:46pm
   
I'm not sure you referenced required assembly (or assemblies) at all. Did you? Do you know how to do it? Where do you have the Cassandra assemblies? In GAC or not?
—SA
johnyjj2 at 19-Apr-13 11:25am
   
Hello,
thanks for your reply. The only what I have done was including in Solution Explorer in Referencews section CassandraSharp (cassandra-sharp-bin-2.3.2\CassandraSharp.dll). I use .NET Framework 4 Client Profile.
Regards!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 162
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100