Example #1
0
        public String ExecProcValue(String procedureName, Dictionary <String, object> procedureParameters, DbConnection connection = null)
        {
            var result = "";
            ConnectionPoolNode node = null;

            try
            {
                if (connection == null)
                {
                    node       = connection_pool.GetNode();
                    connection = node.connection;
                }

                var cmd = MakeCommand(connection, procedureName, procedureParameters);

                DbParameter p_ = cmd.CreateParameter();
                p_.ParameterName = "@value";
                p_.Value         = -1;
                p_.Direction     = ParameterDirection.Output;
                cmd.Parameters.Add(p_);

                try
                {
                    cmd.Prepare();
                    DataTable dt = new DataTable();

                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.FieldCount > 0)
                        {
                            for (int i = 0; i < dr.FieldCount; i++)
                            {
                                DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                                dt.Columns.Add(dc);
                            }
                            object[] rowobject = new object[dr.FieldCount];
                            while (dr.Read())
                            {
                                dr.GetValues(rowobject);
                                dt.LoadDataRow(rowobject, true);
                            }
                        }
                    }

                    result = cmd.Parameters["@value"].Value.ToString();
                }
                finally
                {
                    cmd.Dispose();
                }
            }
            finally
            {
                if (node != null)
                {
                    node.Free();
                }
            }
            return(result);
        }
Example #2
0
        public ConnectionPoolNode GetNode()
        {
            if (Pool == null)
            {
                return(new ConnectionPoolNode(this, -1));
            }
            int i  = 0;
            var ep = DateTime.Now;

            while (true)
            {
                if (Pool[i] == null || (Pool[i] != null && !Pool[i].state))
                {
                    break;
                }

                i++;

                if (i >= Pool.Length)
                {
                    i = 0;
                    Thread.Sleep(30);
                }
            }
            lock (this)
            {
                if (Pool[i] == null)
                {
                    Pool[i] = new ConnectionPoolNode(this, i);
                }
                Pool[i].state = true;
            }
            Pool[i].Connect(this.connection_string, this.provider_name);
            return(Pool[i]);
        }
Example #3
0
        public DataTable ExecProc(String procedureName, Dictionary <String, object> procedureParameters, DbConnection connection = null, Boolean silent = false)
        {
            ConnectionPoolNode node = null;
            DataTable          dt   = null;

            try
            {
                if (connection == null)
                {
                    node       = connection_pool.GetNode();
                    connection = node.connection;
                }

                var cmd = MakeCommand(connection, procedureName, procedureParameters);

                try
                {
                    cmd.Prepare();

                    dt = new DataTable();
                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.FieldCount > 0)
                        {
                            for (int i = 0; i < dr.FieldCount; i++)
                            {
                                DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                                dt.Columns.Add(dc);
                            }
                            object[] rowobject = new object[dr.FieldCount];
                            while (dr.Read())
                            {
                                dr.GetValues(rowobject);
                                dt.LoadDataRow(rowobject, true);
                            }
                        }
                    }
                }
                finally
                {
                    cmd.Dispose();
                }
            }
            finally
            {
                node.Free();
            }

            return(dt);
        }