CqlSharp.CqlConnection.Open C# (CSharp) Метод

Open() публичный Метод

Opens a database connection with the settings specified by the .
public Open ( ) : void
Результат void
        public override void Open()
        {
            if(State != ConnectionState.Closed)
                throw new InvalidOperationException("Connection must be closed before it is opened");

            if(Cluster.IsOpen)
            {
                //perform fast path to open
                OpenAsyncInternal(CancellationToken.None).Wait();
            }
            else
                OpenInternal();
        }

Usage Example

Пример #1
0
        public void Init()
        {
            const string createKsCql =
                @"CREATE KEYSPACE Test WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1} and durable_writes = 'false';";
            const string createTableCql = @"create table Test.BasicFlow (id int primary key, value text);";
            const string truncateTableCql = @"truncate Test.BasicFlow;";

            using (var connection = new CqlConnection(ConnectionString))
            {
                connection.Open();

                try
                {
                    var createKs = new CqlCommand(connection, createKsCql);
                    createKs.ExecuteNonQuery();
                }
                catch (AlreadyExistsException)
                {
                    //ignore
                }

                try
                {
                    var createTable = new CqlCommand(connection, createTableCql);
                    createTable.ExecuteNonQuery();
                }
                catch (AlreadyExistsException)
                {
                    var truncTable = new CqlCommand(connection, truncateTableCql);
                    truncTable.ExecuteNonQuery();
                }
            }
        }
All Usage Examples Of CqlSharp.CqlConnection::Open