Open() public method

public Open ( ) : void
return void
示例#1
0
        public void OpenForAdmin()
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName = AdminUserName,
                Password = AdminPassword,
                DataSource = "memory",
                Database = DatabaseName,
                Schema = "APP",
                Create = true
            };

            var connection = new DeveelDbConnection(connString);
            Assert.AreEqual(ConnectionState.Closed, connection.State);
            Assert.DoesNotThrow(() => connection.Open());
            Assert.AreEqual(ConnectionState.Open, connection.State);
            Assert.DoesNotThrow(() => connection.Close());
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }
示例#2
0
        public void OpenForAdmin()
        {
            var connString = new DeveelDbConnectionStringBuilder {
                UserName   = AdminUserName,
                Password   = AdminPassword,
                DataSource = "memory",
                Database   = DatabaseName,
                Schema     = "APP",
                Create     = true
            };

            var connection = new DeveelDbConnection(connString);

            Assert.AreEqual(ConnectionState.Closed, connection.State);
            Assert.DoesNotThrow(() => connection.Open());
            Assert.AreEqual(ConnectionState.Open, connection.State);
            Assert.DoesNotThrow(() => connection.Close());
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }
示例#3
0
        public void TestSetUp()
        {
            connection = (DeveelDbConnection)system.GetConnection(AdminUser, AdminPassword);
            if (connection.State != ConnectionState.Open)
                connection.Open();

            OnTestSetUp();
        }
示例#4
0
        public void ExecuteScalarOnsingleColumn()
        {
            const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb;BootOrCreate=true";
            var connection = new DeveelDbConnection(connString);
            connection.Open();

            // TODO: Open the connection, create a transaction, declare some variables

            DeveelDbCommand command = null;
            Assert.DoesNotThrow(() => command = connection.CreateCommand());
            Assert.IsNotNull(command);
            command.CommandText = "SELECT Age FROM Person WHERE Name = 'antonello'";
        }
示例#5
0
        ///<summary>
        /// Makes a connection to the database and returns a <see cref="IDbConnection"/> 
        /// object that can be used to execute queries on the database.
        ///</summary>
        ///<param name="schema">The initial database schema to start the connection in.</param>
        ///<param name="username">The user to login to the database under.</param>
        ///<param name="password">The password of the user.</param>
        /// <remarks>
        /// This is a standard connection that talks directly with the database without 
        /// having to go through any communication protocol layers.
        /// <para>
        /// For example, if this control is for a database server, the <see cref="IDbConnection"/>
        /// returned here does not go through the TCP/IP connection.  For this reason certain database 
        /// configuration constraints (such as number of concurrent connection on the database) may not 
        /// apply to this connection.
        /// </para>
        /// </remarks>
        ///<returns>
        /// Returns a <see cref="IDbConnection"/> instance used to access the database.
        /// </returns>
        /// <exception cref="DataException">
        /// Thrown if the login fails with the credentials given.
        /// </exception>
        public IDbConnection GetConnection(string schema, string username, string password)
        {
            // Create the database interface for an internal database connection.
            var localSystem = new LocalSystem(controller);
            var localDatabase = localSystem.ControlDatabase(name);

            // Create the DeveelDbConnection object (very minimal cache settings for an
            // internal connection).
            var s = new DeveelDbConnectionStringBuilder {
                Database = name,
                Schema = schema,
                UserName = username,
                Password = password,
                RowCacheSize = 8,
                MaxCacheSize = 4092000,
                BootOrCreate = true
            };

            if (Config.IsHeapStorageSystem()) {
                s.Host = "Heap";
            } else {
                s.Host = "Local";
                s.Path = Config.DatabaseFullPath();
            }

            int id = ++internalCounter;

            var connection = new DeveelDbConnection(s.ToString(), localDatabase);
            connection.StateChange += (sender, args) => {
                if (args.CurrentState == ConnectionState.Open) {
                    if (connections == null)
                        connections = new Dictionary<int, DeveelDbConnection>();

                    connections[id] = connection;
                } else if (args.CurrentState == ConnectionState.Closed) {
                    connections.Remove(id);
                }
            };

            connection.Disposed += (sender, args) => {
                // TODO: do further disposal
            };

            // Attempt to log in with the given username and password (default schema)
            connection.Open();
            if (connection.State != ConnectionState.Open)
                throw new InvalidOperationException("Unable to open the connection.");

            // And return the new connection
            return connection;
        }