0

We know that when creating a SQL connection, for example:

using (SqlConnection sqlConn = new SqlConnection(conString)); 

we are actually not always creating a new connection to the server, but rather we are taking an already open connection from the connection pool.


However, when we open a connection to the Analysis Services, do we also use some kind of connection pooling?

using (AdomdConnection adomdConn = new AdomdConnection(conString)); 

Does this always lead to a new connection or does it take one from the pool if possible? I am not able to infer this from the official documentation, but I have found mostly older unofficial articles that clearly state there is no connection pooling for AdomdConnection:

1 Answer 1

0
using System; using System.Collections.Concurrent; using Microsoft.AnalysisServices.AdomdClient; public class AdomdConnectionPool { private readonly ConcurrentBag<AdomdConnection> _connectionPool = new ConcurrentBag<AdomdConnection>(); private readonly string _connectionString; public AdomdConnectionPool(string connectionString) { _connectionString = connectionString; } public AdomdConnection GetConnection() { if (_connectionPool.TryTake(out var connection)) { if (connection.State == System.Data.ConnectionState.Open) { return connection; } // Reopen if the connection is closed connection.Open(); return connection; } // Create a new connection if the pool is empty var newConnection = new AdomdConnection(_connectionString); newConnection.Open(); return newConnection; } public void ReturnConnection(AdomdConnection connection) { if (connection != null && connection.State == System.Data.ConnectionState.Open) { _connectionPool.Add(connection); } else { connection?.Dispose(); } } } // Usage var pool = new AdomdConnectionPool("your-connection-string"); using (var conn = pool.GetConnection()) { // Use the connection var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT [Measures].[Sales] ON COLUMNS FROM [Cube]"; var reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader[0]); } pool.ReturnConnection(conn); } 
1
  • The question is more about whether ADOMD provides the pooling by itself, like for sql connections. I understand it can be manually implemented in a way Commented Jan 7 at 15:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.