Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C#
using CassandraSharp.MadeSimple;
using Apache.Cassandra;


It cannot find MadeSimple and Apache. (Other using statements are OK after adding reference to cassandra library).

C#
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:

C#
//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
Comments
Sergey Alexandrovich Kryukov 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900