예제 #1
0
        public CloseResponse Close(CloseRequest request)
        {
            CloseResponse response = new CloseResponse();

            if (StringUtils.IsBlank(request.ConnectionID))
            {
                response.Error = "Blank connection ID.";
            }
            else
            {
                try
                {
                    OdbcConnectionPool.Instance.CloseConnection(request.ConnectionID);
                    response.Success = true;
                }
                catch (OdbcException x)
                {
                    response.Error = OdbcConnectionPool.GetOdbcError(x);
                }
                catch (Exception x)
                {
                    response.Error = x.ToString();
                }
            }

            return(response);
        }
예제 #2
0
        public ConnectResponse Connect(ConnectRequest request)
        {
            ConnectResponse response = new ConnectResponse();

            // Overeni, zda byl zadan Connection string;
            if (StringUtils.IsBlank(request.ConnectionString))
            {
                response.Error = "Blank connection string.";
            }
            else
            {
                // Otevreni ODBC.
                try
                {
                    PooledOdbcConnection pooledOdbcConnection = OdbcConnectionPool.Instance.OdbcConnect(request.ConnectionString, request.UsingOleDb);
                    response.ConnectionID            = pooledOdbcConnection.ID;
                    response.Success                 = true;
                    response.ConnectionAutoCloseTime = pooledOdbcConnection.ConnectionAutoCloseTime;
                }
                catch (OdbcException x)
                {
                    response.Error = OdbcConnectionPool.GetOdbcError(x);
                }
                catch (Exception x)
                {
                    response.Error = x.ToString();
                }
            }

            return(response);
        }
예제 #3
0
        private static void CloseAbandonedConnectionsHandler(object sender, EventArgs e)
        {
            OdbcConnectionPool instance = Instance;

            instance.CloseAbandonedConnections();
            instance.closeAbandonedConnectionsTimer.Start();
        }
예제 #4
0
        public ExecuteResponse ExecuteCommand(ExecuteRequest request)
        {
            ExecuteResponse response = new ExecuteResponse();

            if (StringUtils.IsBlank(request.ConnectionID))
            {
                response.Error = "Blank connection ID.";
            }
            else if (StringUtils.IsBlank(request.Query))
            {
                response.Error = "Query is blank.";
            }
            else
            {
                try
                {
                    PooledOdbcConnection pooledOdbcConnection = OdbcConnectionPool.Instance.GetConnection(request.ConnectionID);

                    if (pooledOdbcConnection.OdbcConnection != null)
                    {
                        OdbcConnection connection = pooledOdbcConnection.OdbcConnection;

                        using (OdbcCommand command = new OdbcCommand(request.Query, connection))
                        {
                            int affectedRows = command.ExecuteNonQuery();
                            response.AffectedRows = affectedRows;
                        }
                    }
                    else
                    {
                        OleDbConnection connection = pooledOdbcConnection.OleDbConnection;

                        using (OleDbCommand command = new OleDbCommand(request.Query, connection))
                        {
                            int affectedRows = command.ExecuteNonQuery();
                            response.AffectedRows = affectedRows;
                        }
                    }

                    response.Success = true;
                    response.ConnectionAutoCloseTime = pooledOdbcConnection.ConnectionAutoCloseTime;
                }
                catch (OdbcException x)
                {
                    response.Error = OdbcConnectionPool.GetOdbcError(x);
                }
                catch (Exception x)
                {
                    response.Error = x.ToString();
                }
            }

            return(response);
        }
예제 #5
0
        public SelectResponse Select(SelectRequest request)
        {
            SelectResponse response = new SelectResponse();

            if (StringUtils.IsBlank(request.ConnectionID))
            {
                response.Error = "Blank connection ID.";
            }
            else if (StringUtils.IsBlank(request.Query))
            {
                response.Error = "Query is blank.";
            }
            else
            {
                try
                {
                    PooledOdbcConnection pooledOdbcConnection = OdbcConnectionPool.Instance.GetConnection(request.ConnectionID);

                    List <RowData> rows = new List <RowData>();
                    response.Rows = rows;

                    if (pooledOdbcConnection.OdbcConnection != null)
                    {
                        OdbcConnection connection = pooledOdbcConnection.OdbcConnection;

                        using (OdbcCommand command = new OdbcCommand(request.Query, connection))
                        {
                            using (OdbcDataReader reader = command.ExecuteReader(CommandBehavior.Default | CommandBehavior.KeyInfo))
                            {
                                if (request.ReturnSchemaTable)
                                {
                                    response.SchemaTable = getSchemaTable(reader);
                                }

                                while (reader.Read())
                                {
                                    RowData rowData = new RowData();
                                    for (int i = 0; i < reader.FieldCount; i++)
                                    {
                                        rowData.Add(reader.GetName(i), getColumnValue(reader, i));
                                    }
                                    rows.Add(rowData);
                                }
                            }
                        }
                    }
                    else
                    {
                        OleDbConnection connection = pooledOdbcConnection.OleDbConnection;

                        using (OleDbCommand command = new OleDbCommand(request.Query, connection))
                        {
                            using (OleDbDataReader reader = command.ExecuteReader(CommandBehavior.Default | CommandBehavior.KeyInfo))
                            {
                                if (request.ReturnSchemaTable)
                                {
                                    response.SchemaTable = getSchemaTable(reader);
                                }

                                while (reader.Read())
                                {
                                    RowData rowData = new RowData();
                                    for (int i = 0; i < reader.FieldCount; i++)
                                    {
                                        rowData.Add(reader.GetName(i), getColumnValue(reader, i));
                                    }
                                    rows.Add(rowData);
                                }
                            }
                        }
                    }

                    response.Success = true;
                    response.ConnectionAutoCloseTime = pooledOdbcConnection.ConnectionAutoCloseTime;
                }
                catch (OdbcException x)
                {
                    response.Error = OdbcConnectionPool.GetOdbcError(x);
                }
                catch (Exception x)
                {
                    response.Error = x.ToString();
                }
            }

            return(response);
        }