Exemple #1
0
 public void TestConnection()
 {
     FirebirdSql.Data.FirebirdClient.FbConnection Conn = new FirebirdSql.Data.FirebirdClient.FbConnection(this.ConnStr);
     Conn.Open();
     Conn.Close();
     Conn.Dispose();
 }
Exemple #2
0
        public void RunScriptFile(string ScriptFile)
        {
            if (!System.IO.File.Exists(ScriptFile))
            {
                throw new Exception("File '" + ScriptFile + "' does not exist.");
            }

            System.IO.StreamReader sr = null;
            try {
                sr = new System.IO.StreamReader(ScriptFile, false);

                using (FirebirdSql.Data.FirebirdClient.FbConnection conn = new FirebirdSql.Data.FirebirdClient.FbConnection(this.ConnStr)) {
                    conn.Open();

                    using (FirebirdSql.Data.FirebirdClient.FbCommand cmd = new FirebirdSql.Data.FirebirdClient.FbCommand()) {
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = sr.ReadToEnd();

                        cmd.ExecuteNonQuery();
                    }

                    conn.Close();
                }
            } catch (Exception ex) {
                throw ex;
            } finally {
                sr.Close();
                sr.Dispose();
            }
        }
Exemple #3
0
        private void bTEST_Click(object sender, EventArgs e)
        {
            try
            {
                using (FirebirdSql.Data.FirebirdClient.FbConnection fbc = new FirebirdSql.Data.FirebirdClient.FbConnection((new clDBInfo(tbDBName.Text, cbServer.Text, tbDBPath.Text, tbUser.Text, tbPassword.Text)).GetFbConnStr()))
                {
                    fbc.Open();
                    FbServerProperties fbsp = new FbServerProperties();
                    fbsp.ConnectionString = (new clDBInfo(tbDBName.Text, cbServer.Text, tbDBPath.Text, tbUser.Text, tbPassword.Text)).GetFbConnStr();
                    string msg = "";
                    foreach (string s in fbsp.DatabasesInfo.Databases)
                    {
                        msg = msg + "\n" + s;
                    }
                    MessageBox.Show(string.Format("к серверу {0} успешно установлено соединение.\nВсего соединений к серверу БД: {1}\n {2}", cbServer.Text, fbsp.DatabasesInfo.ConnectionCount, msg));


                    fbc.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public DatabaseModel Create(DbConnection connection, IEnumerable <string> tables, IEnumerable <string> schemas)
        {
            ResetState();

            _connection = (FirebirdClientConnection)connection;

            var connectionStartedOpen = _connection.State == ConnectionState.Open;

            if (!connectionStartedOpen)
            {
                _connection.Open();
            }
            try
            {
                _databaseModel.DatabaseName = _connection.Database;
                _serverVersion = Data.Services.FbServerProperties.ParseServerVersion(_connection.ServerVersion);
#warning Finish
                return(_databaseModel);
            }
            finally
            {
                if (!connectionStartedOpen)
                {
                    _connection.Close();
                }
            }
        }
        private void bTEST_Click(object sender, EventArgs e)
        {
            try
            {

                using (FirebirdSql.Data.FirebirdClient.FbConnection fbc = new FirebirdSql.Data.FirebirdClient.FbConnection((new clDBInfo(tbDBName.Text, cbServer.Text, tbDBPath.Text, tbUser.Text, tbPassword.Text)).GetFbConnStr()))
                {
                    fbc.Open();
                    FbServerProperties fbsp = new FbServerProperties();
                        fbsp.ConnectionString = (new clDBInfo(tbDBName.Text, cbServer.Text, tbDBPath.Text, tbUser.Text, tbPassword.Text)).GetFbConnStr();
                        string msg = "";
                        foreach (string s in fbsp.DatabasesInfo.Databases)
                        {
                            msg = msg + "\n" + s;
                        }
                        MessageBox.Show(string.Format("к серверу {0} успешно установлено соединение.\nВсего соединений к серверу БД: {1}\n {2}", cbServer.Text, fbsp.DatabasesInfo.ConnectionCount, msg));

                    fbc.Close();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void firebird()
        {
            //var connector = DataSources.Get("Results");


            // List list = new List<KeyValuePair<string, string>>();

            string con_string =
                "User=SYSDBA;" +
                "Password=masterkey;" +
                "Database=C:\\Program Files (x86)\\Firebird\\Firebird_3_0\\examples\\empbuild\\employee.FDB;" +
                "DataSource=localhost;" +
                "Port=3050;" +
                // "Dialect=3;" +
                "Charset=NONE;" +
                "Role=";

            /*
             * "Connection lifetime=15;" +
             * "Pooling=true;" +
             * "MinPoolSize=0;" +
             * "MaxPoolSize=50;" +
             * "Packet Size=8192;" +
             * "ServerType=0";
             */



            FirebirdSql.Data.FirebirdClient.FbConnection con = new FirebirdSql.Data.FirebirdClient.FbConnection(con_string);

            con.Open();
            Ranorex.Report.Info(con.ServerVersion.ToString());


            string query = "SELECT a.COUNTRY, a.CURRENCY FROM COUNTRY a";

            FirebirdSql.Data.FirebirdClient.FbCommand    command = new FirebirdSql.Data.FirebirdClient.FbCommand(query, con);
            FirebirdSql.Data.FirebirdClient.FbDataReader reader  = command.ExecuteReader();

            DataTable datatable = new DataTable();

            datatable.Load(reader);


            con.Close();

            int rows = datatable.Rows.Count;

            if (rows > 0)
            {
                for (int i = 0; i < rows; i++)
                {
                    string[] stringData = Array.ConvertAll <object, string>(datatable.Rows[i].ItemArray.ToArray(), o => o.ToString());
                    Ranorex.Report.Info("Country: " + datatable.Rows[i][0] + " Currency: " + datatable.Rows[i][1]);
                    //list.add(new KeyValuePair<string, int>("A", 1));
                }
            }
        }
Exemple #7
0
        public DataTable TestQuery(string Query)
        {
            using (FirebirdSql.Data.FirebirdClient.FbConnection conn = new FirebirdSql.Data.FirebirdClient.FbConnection(this.ConnStr)) {
                conn.Open();

                using (FirebirdSql.Data.FirebirdClient.FbCommand cmd = new FirebirdSql.Data.FirebirdClient.FbCommand()) {
                    cmd.Connection  = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = Query;

                    DataTable dt = new DataTable();
                    using (FirebirdSql.Data.FirebirdClient.FbDataAdapter da = new FirebirdSql.Data.FirebirdClient.FbDataAdapter(cmd)) {
                        da.Fill(dt);
                    }

                    conn.Close();
                    return(dt);
                }
            }
        }
Exemple #8
0
        public List <SchemaRow> GetSchema()
        {
            if (!string.IsNullOrEmpty(this.ColumnSchemaQuery))
            {
                if (this.ColumnSchemaQuery.IndexOf(this.TableNamePlaceHolder) == -1)
                {
                    throw new Exception("Required placeholder for table name: '" + this.TableNamePlaceHolder + "'.");
                }
            }

            List <SchemaRow> Schema = new List <SchemaRow>();

            using (FirebirdSql.Data.FirebirdClient.FbConnection conn = new FirebirdSql.Data.FirebirdClient.FbConnection(this.ConnStr)) {
                conn.Open();

                //Using single result set
                if (!string.IsNullOrEmpty(this.SchemaQuery))
                {
                    using (FirebirdSql.Data.FirebirdClient.FbCommand cmd = new FirebirdSql.Data.FirebirdClient.FbCommand()) {
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = this.SchemaQuery;

                        DataTable dtSchema = new DataTable();
                        using (FirebirdSql.Data.FirebirdClient.FbDataAdapter da = new FirebirdSql.Data.FirebirdClient.FbDataAdapter(cmd)) {
                            da.Fill(dtSchema);
                        }

                        conn.Close();

                        foreach (DataRow dr in dtSchema.Rows)
                        {
                            Schema.Add(this.SetColumnAttributes(dr["TABLE_NAME"].ToString(), dr["TABLE_TYPE"].ToString(), dr));
                        }

                        return(Schema);
                    }
                }

                //Way of the Table/Column

                //Retrieve table schema first
                List <SchemaRow> TableSchema = new List <SchemaRow>();
                if (!string.IsNullOrEmpty(this.TableSchemaQuery))
                {
                    //Using table schema query
                    using (FirebirdSql.Data.FirebirdClient.FbCommand cmd = new FirebirdSql.Data.FirebirdClient.FbCommand()) {
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = this.TableSchemaQuery;

                        DataTable dtTableSchema = new DataTable();
                        using (FirebirdSql.Data.FirebirdClient.FbDataAdapter da = new FirebirdSql.Data.FirebirdClient.FbDataAdapter(cmd)) {
                            da.Fill(dtTableSchema);
                        }

                        TableSchema = this.GetInitialTables(dtTableSchema);
                    }
                }
                else
                {
                    //Get by default using GetSchema
                    DataTable dtTableSchema = new DataTable();
                    dtTableSchema = conn.GetSchema(System.Data.SqlClient.SqlClientMetaDataCollectionNames.Tables);
                    TableSchema   = this.GetInitialTables(dtTableSchema);
                }


                //Get columns for each table
                if (!string.IsNullOrEmpty(this.ColumnSchemaQuery))
                {
                    //Use column schema query
                    foreach (SchemaRow tsr in TableSchema)
                    {
                        DataTable dtColumnSchema = new DataTable();

                        using (FirebirdSql.Data.FirebirdClient.FbCommand cmd = new FirebirdSql.Data.FirebirdClient.FbCommand()) {
                            cmd.Connection  = conn;
                            cmd.CommandType = CommandType.Text;
                            cmd.CommandText = this.ColumnSchemaQuery.Replace(this.TableNamePlaceHolder, tsr.Name);

                            using (FirebirdSql.Data.FirebirdClient.FbDataAdapter da = new FirebirdSql.Data.FirebirdClient.FbDataAdapter(cmd)) {
                                da.Fill(dtColumnSchema);
                            }
                        }

                        //Get column schema
                        foreach (DataRow dr in dtColumnSchema.Rows)
                        {
                            Schema.Add(this.SetColumnAttributes(tsr.Name, tsr.Type, dr));
                        }
                    }
                }

                conn.Close();
            }

            return(Schema);
        }