Пример #1
0
		internal override void LoadAll()
		{
			try
			{
				MetaHelper mh = new MetaHelper();
				string dbName = mh.LoadDatabases(this.dbRoot.ConnectionString);

				VistaDBDatabase database = (VistaDBDatabase)this.dbRoot.ClassFactory.CreateDatabase();

				database._name = dbName;
				database.dbRoot = this.dbRoot;
				database.Databases = this;

				this._array.Add(database);
			}
			catch {}
		}
Пример #2
0
        internal override void LoadAll()
        {
            try
            {
                MetaHelper mh     = new MetaHelper();
                string     dbName = mh.LoadDatabases(this.dbRoot.ConnectionString);

                VistaDBDatabase database = (VistaDBDatabase)this.dbRoot.ClassFactory.CreateDatabase();

                database._name     = dbName;
                database.dbRoot    = this.dbRoot;
                database.Databases = this;

                this._array.Add(database);
            }
            catch {}
        }
Пример #3
0
        /// <summary>
        /// Same as <see cref="Connect(string, string)"/>(string, string) only this uses an enumeration.  
        /// </summary>
        /// <param name="driver">The driver enumeration for you DBMS system</param>
        /// <param name="pluginName">The name of the plugin</param>
        /// <param name="connectionString">A valid connection string for you DBMS</param>
        /// <returns></returns>
        public bool Connect(dbDriver driver, string pluginName, string connectionString)
        {
            Reset();

            string dbName;
            int index;

            _connectionString = connectionString.Replace("\"", "");
            _driver = driver;

            #region not fully implemented yet

/*
            InternalDriver drv = InternalDriver.Get(settings.DbDriver);
            if (drv != null)
            {
                this._driverString = drv.DriverId;
                this.StripTrailingNulls = drv.StripTrailingNulls;
                this.requiredDatabaseName = drv.RequiredDatabaseName;

                IDbConnection con = null;
		        try
		        {
                    ClassFactory = drv.CreateBuildInClass();
                    if (ClassFactory != null)
                        con = ClassFactory.CreateConnection();
                    else
                    {
                        IMyMetaPlugin plugin = drv.CreateMyMetaPluginClass();
                        if (plugin != null)
                        {
                            MyMetaPluginContext pluginContext = new MyMetaPluginContext(drv.DriverId, this._connectionString);
                            plugin.Initialize(pluginContext);
                            con = plugin.NewConnection;
                        }
                    }
                    if (con != null)
                    {
                        con.ConnectionString = this._connectionString;
			            // cn.Open();
                    }
			        this._defaultDatabase = drv.GetDataBaseName(cn);
		        }
		        catch(Exception Ex)
		        {
			        throw Ex;
		        } finally {
                    if (con != null)
			            cn.Close();
                }
            }
            else
            {
                // Error
            }           
*/

            #endregion not fully implemented yet

            switch (_driver)
            {
                case dbDriver.SQL:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.SQL;
                    StripTrailingNulls = false;
                    requiredDatabaseName = true;
                    ClassFactory = new ClassFactory();
                    break;

                case dbDriver.Oracle:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.Oracle;
                    StripTrailingNulls = false;
                    requiredDatabaseName = true;
                    ClassFactory = new Oracle.ClassFactory();
                    break;

                case dbDriver.Access:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.Access;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new Access.ClassFactory();
                    break;

                case dbDriver.MySql:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.MySql;
                    StripTrailingNulls = true;
                    requiredDatabaseName = true;
                    ClassFactory = new MySql.ClassFactory();
                    break;

                case dbDriver.MySql2:

                    using (var mysqlconn = new MySqlConnection(_connectionString))
                    {
                        mysqlconn.Close();
                        mysqlconn.Open();
                        _defaultDatabase = mysqlconn.Database;
                    }

                    _driverString = MyMetaDrivers.MySql2;
                    StripTrailingNulls = true;
                    requiredDatabaseName = true;
                    ClassFactory = new MySql5.ClassFactory();
                    break;

                case dbDriver.DB2:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.DB2;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new DB2.ClassFactory();
                    break;

                case dbDriver.ISeries:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.ISeries;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new ISeries.ClassFactory();
                    break;

                case dbDriver.Pervasive:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.Pervasive;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new Pervasive.ClassFactory();
                    break;

                case dbDriver.PostgreSQL:

                    using (var cn = new NpgsqlConnection(_connectionString))
                    {
                        cn.Open();
                        _defaultDatabase = cn.Database;
                    }

                    _driverString = MyMetaDrivers.PostgreSQL;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new PostgreSQL.ClassFactory();
                    break;

                case dbDriver.PostgreSQL8:

                    using (var cn8 = new NpgsqlConnection(_connectionString))
                    {
                        cn8.Open();
                        _defaultDatabase = cn8.Database;
                    }

                    _driverString = MyMetaDrivers.PostgreSQL8;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new PostgreSQL8.ClassFactory();
                    break;

                case dbDriver.Firebird:

                    using (var cn1 = new FbConnection(_connectionString))
                    {
                        cn1.Open();
                        dbName = cn1.Database;
                    }

                    try
                    {
                        index = dbName.LastIndexOfAny(new[] {'\\'});
                        if (index >= 0)
                        {
                            _defaultDatabase = dbName.Substring(index + 1);
                        }
                    }
                    catch {}

                    _driverString = MyMetaDrivers.Firebird;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new Firebird.ClassFactory();
                    break;

                case dbDriver.Interbase:

                    using (var cn2 = new FbConnection(_connectionString))
                    {
                        cn2.Open();
                        _defaultDatabase = cn2.Database;
                    }

                    _driverString = MyMetaDrivers.Interbase;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new Firebird.ClassFactory();
                    break;

                case dbDriver.SQLite:

                    using (var sqliteConn = new SQLiteConnection(_connectionString))
                    {
                        sqliteConn.Open();
                        dbName = sqliteConn.Database;
                    }
                    _driverString = MyMetaDrivers.SQLite;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new SQLite.ClassFactory();
                    break;
#if !IGNORE_VISTA
                case dbDriver.VistaDB:

                    try
                    {
                        var mh = new MetaHelper();
                        dbName = mh.LoadDatabases(_connectionString);

                        if (dbName == "") return false;

                        _defaultDatabase = dbName;

                        _driverString = MyMetaDrivers.VistaDB;
                        StripTrailingNulls = false;
                        requiredDatabaseName = false;
                        ClassFactory = new VistaDB.ClassFactory();
                    }
                    catch
                    {
                        throw new Exception("Invalid VistaDB connection or VistaDB not installed");
                    }

                    break;
#endif
                case dbDriver.Advantage:

                    ConnectUsingOleDb(_driver, _connectionString);
                    _driverString = MyMetaDrivers.Advantage;
                    StripTrailingNulls = false;
                    requiredDatabaseName = false;
                    ClassFactory = new Advantage.ClassFactory();
                    string[] s = _defaultDatabase.Split('.');
                    _defaultDatabase = s[0];
                    break;

                case dbDriver.Plugin:
                    break;

                case dbDriver.None:

                    _driverString = MyMetaDrivers.None;
                    break;
            }

            _isConnected = true;
            return true;
        }
Пример #4
0
        public IDbConnection BuildConnection(string driver, string connectionString)
        {
            IDbConnection conn = null;
            switch (driver.ToUpper())
            {
                case MyMetaDrivers.MySql2:
                    conn = new MySqlConnection(connectionString);
                    break;

                case MyMetaDrivers.PostgreSQL:
                case MyMetaDrivers.PostgreSQL8:
                    conn = new NpgsqlConnection(connectionString);
                    break;

                case MyMetaDrivers.Firebird:
                case MyMetaDrivers.Interbase:
                    conn = new FbConnection(connectionString);
                    break;

                case MyMetaDrivers.SQLite:
                    conn = new SQLiteConnection(connectionString);
                    break;
#if !IGNORE_VISTA
                case MyMetaDrivers.VistaDB:
                    try
                    {
                        var mh = new MetaHelper();
                        conn = mh.GetConnection(connectionString);
                    }
                    catch
                    {
                        throw new Exception("Invalid VistaDB connection or VistaDB not installed");
                    }
                    break;
#endif
                default:
                    break;
            }
            return conn;
        }