1. Using Microsoft Visual Studio, Create New Project for Console Application
2. Configure the project
3. My target Framework using NET 5.0
4. Add Client Driver for Cassandra, click Tools menu ->NuGet Package Manager-> Manage NuGet Packages for Solution, then type CassandraCSharpDriver
so CassandraCSharpDriver package get installed
5. Create program
using System.Collections;
using System.Collections.Generic;
using Cassandra;
using Cassandra.Mapping;
namespace Cassandra_con
{
public class KeyspacesMain
{
public string Keyspace_name { get; set; }
public bool Durable_writes { get; set; }
public SortedDictionary<string string=""> Replication { get; set; }
}
class Program
{
const string MyDC = "datacenter1";
const string MyIP = "localhost";
const int MyPortNo = 9042;
const string MyUID = "username";
const string MyPass = "password";
static void Main(string[] args)
{
Console.WriteLine("Hello Cassandra!");
.AddContactPoints(MyIP)
.WithPort(MyPortNo)
// .WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy(MyDC))
// .WithAuthProvider(new PlainTextAuthProvider(MyUID, MyPass))
.Build();
Console.WriteLine("Connected to cluster: " + cluster.Metadata.ClusterName);
IMapper mapper = new Mapper(session);
IEnumerable<keyspacesmain> datax = mapper.Fetch<keyspacesmain>("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces");
Console.WriteLine("Keyspace Name Durable Writes Replication Factor");
{
Console.Write("{0}", row.Keyspace_name.PadRight(19));
Console.Write("{0} ", row.Durable_writes);
int spaces = 12;
while (dictEnum.MoveNext())
{
Console.WriteLine("Key= ".PadLeft(spaces) + dictEnum.Key + ", Value= " + dictEnum.Value);
spaces += 28;
}
}
}
}
}