Example #1
0
        /// <summary>
        ///        Creates a new connection. If this is the first connection,  it also creates an extra
        ///        "Keep Alive" connection to keep the database open.
        /// If <paramref name="usePooledConnection"/> is true, than if this connection has been opened before,
        /// the connection from the pool will be returned rather than creating a new one.
        /// </summary>
        /// <param name="db">The database instance that will be used to create a connection.</param>
        /// <param name="usePooledConnection">If true, return an already created connection for this object. If
        /// false, always create a new one.</param>
        /// <returns>A new connection.</returns>
        public static DatabaseConnectionWrapper CreateConnection(SqlCeDatabase db, bool usePooledConnection)
        {
            string connectionString = db.ConnectionStringWithoutCredentials;
            DatabaseConnectionWrapper connection;

            lock (connections)
            {
                if (!connections.TryGetValue(connectionString, out connection))
                {
                    //
                    // We have to test this again in case another thread added a connection.
                    //
                    if (!connections.ContainsKey(connectionString))
                    {
                        DbConnection keepAliveConnection = new SqlCeConnection();
                        db.SetConnectionString(keepAliveConnection);
                        keepAliveConnection.Open();
                        connection = new DatabaseConnectionWrapper(keepAliveConnection);
                        connections.Add(connectionString, connection);
                    }
                }
                if (usePooledConnection)
                {
                    connection.AddRef();
                    return(connection);
                }

                return(new DatabaseConnectionWrapper(new SqlCeConnection()));
            }
        }
Example #2
0
        public static DbConnection CreateConnection(SqlCeDatabase db)
        {
            string connectionString = db.ConnectionStringWithoutCredentials;

            if (!connections.ContainsKey(connectionString))
            {
                lock (connections)
                {
                    if (!connections.ContainsKey(connectionString))
                    {
                        DbConnection keepAliveConnection = new SqlCeConnection();
                        db.SetConnectionString(keepAliveConnection);
                        keepAliveConnection.Open();
                        connections.Add(connectionString, keepAliveConnection);
                    }
                }
            }
            return(new SqlCeConnection());
        }
		/// <summary>
		///		Creates a new connection. If this is the first connection,  it also creates an extra
		///		"Keep Alive" connection to keep the database open.
		/// </summary>
		/// <param name="db">The database instance that will be used to create a connection.</param>
		/// <returns>A new connection.</returns>
		internal static DbConnection CreateConnection(SqlCeDatabase db)
		{
			string connectionString = db.ConnectionStringWithoutCredentials;

			if (!connections.ContainsKey(connectionString))
			{
				lock (connections)
				{
					//
					// We have to test this again in case another thread added a connection.
					//
					if (!connections.ContainsKey(connectionString))
					{
						DbConnection keepAliveConnection = new SqlCeConnection();
						db.SetConnectionString(keepAliveConnection);
                        keepAliveConnection.Open();
						
						connections.Add(connectionString, keepAliveConnection);
					}
				}
			}

			return new SqlCeConnection();
		}
Example #4
0
        /// <summary>
        ///		Creates a new connection. If this is the first connection,  it also creates an extra
        ///		"Keep Alive" connection to keep the database open.
        /// </summary>
        /// <param name="db">The database instance that will be used to create a connection.</param>
        /// <returns>A new connection.</returns>
        internal static DbConnection CreateConnection(SqlCeDatabase db)
        {
            string connectionString = db.ConnectionStringWithoutCredentials;

            if (!connections.ContainsKey(connectionString))
            {
                lock (connections)
                {
                    //
                    // We have to test this again in case another thread added a connection.
                    //
                    if (!connections.ContainsKey(connectionString))
                    {
                        DbConnection keepAliveConnection = new SqlCeConnection();
                        db.SetConnectionString(keepAliveConnection);
                        keepAliveConnection.Open();

                        connections.Add(connectionString, keepAliveConnection);
                    }
                }
            }

            return(new SqlCeConnection());
        }
        /// <summary>
        ///		Creates a new connection. If this is the first connection,  it also creates an extra
        ///		"Keep Alive" connection to keep the database open.
        /// If <paramref name="usePooledConnection"/> is true, than if this connection has been opened before,
        /// the connection from the pool will be returned rather than creating a new one.
        /// </summary>
        /// <param name="db">The database instance that will be used to create a connection.</param>
        /// <param name="usePooledConnection">If true, return an already created connection for this object. If
        /// false, always create a new one.</param>
        /// <returns>A new connection.</returns>
        public static DatabaseConnectionWrapper CreateConnection(SqlCeDatabase db, bool usePooledConnection)
        {
            string connectionString = db.ConnectionStringWithoutCredentials;
            DatabaseConnectionWrapper connection;
            lock (connections)
            {
                if (!connections.TryGetValue(connectionString, out connection))
                {
                    //
                    // We have to test this again in case another thread added a connection.
                    //
                    if (!connections.ContainsKey(connectionString))
                    {
                        DbConnection keepAliveConnection = new SqlCeConnection();
                        db.SetConnectionString(keepAliveConnection);
                        keepAliveConnection.Open();
                        connection = new DatabaseConnectionWrapper(keepAliveConnection);
                        connections.Add(connectionString, connection);
                    }
                }
                if (usePooledConnection)
                {
                    connection.AddRef();
                    return connection;
                }

                return new DatabaseConnectionWrapper(new SqlCeConnection());
            }
        }