Beispiel #1
0
        public CellSet ExecuteQuery(string query, ref String sessionId)
        {
            try
            {
                if (Connection != null)
                {
                    AdomdConnection conn = AdomdConnectionPool.GetConnection(Connection.ConnectionString, sessionId);
                    lock (conn)
                    {
                        sessionId = conn.SessionID;
                        using (AdomdCommand cmd = new AdomdCommand(query, conn))
                        {
                            DateTime start = DateTime.Now;
                            CellSet  cs    = cmd.ExecuteCellSet();
                            System.Diagnostics.Debug.WriteLine("MDX query executimg time: " + (DateTime.Now - start).ToString());

                            return(cs);
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("{0} ExecuteQuery ERROR: {1}\r\n Connection String: {2} \r\n Query: {3}\r\n",
                                                    DateTime.Now.ToString(), ex.ToString(), Connection.ConnectionString, query);
                throw ex;
            }
        }
Beispiel #2
0
 public int ExecuteNonQuery(String query, ref String sessionId)
 {
     try
     {
         if (Connection != null)
         {
             AdomdConnection conn = AdomdConnectionPool.GetConnection(Connection.ConnectionString, sessionId);
             lock (conn)
             {
                 sessionId = conn.SessionID;
                 using (AdomdCommand cmd = new AdomdCommand(query, conn))
                 {
                     return(cmd.ExecuteNonQuery());
                 }
             }
         }
         return(0);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.TraceError("{0} ExecuteNonQuery ERROR: {1}\r\n Connection String: {2} \r\n Query: {3}\r\n",
                                             DateTime.Now.ToString(), ex.ToString(), Connection.ConnectionString, query);
         throw;
     }
 }
Beispiel #3
0
        public DataTable ExecuteReader(string query, ref String sessionId)
        {
            try
            {
                if (Connection != null)
                {
                    AdomdConnection conn = AdomdConnectionPool.GetConnection(Connection.ConnectionString, sessionId);
                    lock (conn)
                    {
                        sessionId = conn.SessionID;
                        using (AdomdCommand cmd = new AdomdCommand(query, conn))
                        {
                            DateTime start = DateTime.Now;
                            using (var reader = cmd.ExecuteReader())
                            {
                                if (reader != null)
                                {
                                    DataTable table          = new DataTable();
                                    var       metadata_table = reader.GetSchemaTable();
                                    if (metadata_table != null)
                                    {
                                        foreach (DataRow row in metadata_table.Rows)
                                        {
                                            table.Columns.Add(new DataColumn(row[0].ToString()));
                                        }
                                    }

                                    if (table.Columns.Count >= reader.FieldCount)
                                    {
                                        while (reader.Read())
                                        {
                                            var values = new object[reader.FieldCount];
                                            for (int i = 0; i < reader.FieldCount; i++)
                                            {
                                                values[i] = reader[i];
                                            }
                                            table.Rows.Add(values);
                                        }
                                    }
                                    System.Diagnostics.Debug.WriteLine("ExecuteReader executimg time: " + (DateTime.Now - start).ToString());
                                    return(table);
                                }
                            }
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("{0} ExecuteReader ERROR: {1}\r\n Connection String: {2} \r\n Query: {3}\r\n",
                                                    DateTime.Now.ToString(), ex.ToString(), Connection.ConnectionString, query);
                throw ex;
            }
        }