Exemplo n.º 1
0
        public void InitDbs(string conn)
        {
            if (conn == "")
            {
                string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                assemblyFolder = assemblyFolder.Replace("\\Debug", "");
                assemblyFolder = assemblyFolder.Replace("\\bin", "");
                assemblyFolder = assemblyFolder.Replace("\\netcoreapp2.1", "");

                assemblyFolder = assemblyFolder.Replace("file:\\", "");
                string  text = System.IO.File.ReadAllText(assemblyFolder + @"\appsettings.json");
                dynamic o    = Newtonsoft.Json.JsonConvert.DeserializeObject <appSetting>(text);
                conn = o.Conn;

                if (conn == null)
                {
                    conn = DbConnection;
                }
            }
            //Modify the connections to suit
            //Comment any databases that should not be executed against
            DBDatabase mysql = DBDatabase.Create("MySQL"
                                                 , conn
                                                 , DbProvider);

            this._database = mysql;
            this._database.HandleException += new DBExceptionHandler(database_HandleException);
            var il = conn.Split(';').Where(x => x.ToLower().IndexOf("initial") >= 0).ToList();

            if (il.Count > 0)
            {
                _Schema = il[0].ToLower().Replace("initial catalog=", "");
                _Schema = _Schema.Replace("database=", "");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new DBDatabase referring to the constants DBConnection and DBProvider
        /// </summary>
        /// <returns></returns>
        public static DBDatabase CreateDB()
        {
            DBDatabase db = DBDatabase.Create(Nw.DbConnection, Nw.DbProvider);

            //requires valid connection
            //Console.WriteLine("DataBase '" + db.ProviderName + "' properties: " + db.DBProperties.ToString());

            return(db);
        }
Exemplo n.º 3
0
        public void InitDbs(string conn)
        {
            //Modify the connections to suit
            //Comment any databases that should not be executed against
            DBDatabase mysql = DBDatabase.Create("MySQL"
                                                 , conn
                                                 , DbProvider);

            this._database = mysql;
            this._database.HandleException += new DBExceptionHandler(database_HandleException);
        }
Exemplo n.º 4
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ClientConnection con = new ClientConnection();

            if (con.ShowDialog(this) == DialogResult.OK)
            {
                database = DBDatabase.Create(con.ConnectionString, con.ProviderName);
                provider = database.GetSchemaProvider();
                this.LoadSchemaTree();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates and returns a reference to a (non-existant) Oracle Database
        /// </summary>
        /// <returns></returns>
        private static DBDatabase GetOracleDB()
        {
            DBDatabase db = CreateDB();

            if (db.ProviderName != Oracle.DBOracleImplementation.OracleProviderName)
            {
                Console.WriteLine("Running with NON Oracle Provider - so everything will fail. Only oracle provider supports the Squence generation");
                Console.WriteLine("Switching to oracle provider");
                //Doesn't need to exist to run the tests
                db = DBDatabase.Create("DATA SOURCE=0.0.0.0;PERSIST SECURITY INFO=True;USER ID=NONE;PASSWORD=NONE", Oracle.DBOracleImplementation.OracleProviderName);
            }
            return(db);
        }
Exemplo n.º 6
0
        private bool ChooseConnection()
        {
            ClientConnection con = new ClientConnection();

            if (con.ShowDialog() == DialogResult.OK)
            {
                database = DBDatabase.Create(con.ConnectionString, con.ProviderName);
                provider = database.GetSchemaProvider();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        public void InitDbs(string conn)
        {
            string    dataProvider            = @"MySql.Data.MySqlClient";
            string    dataProviderDescription = @".Net Framework Data Provider for MySQL";
            string    dataProviderName        = @"MySQL Data Provider";
            string    dataProviderType        = @"MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.19.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d";
            DataTable dt = new DataTable();

            dt.Columns.Add("Name");
            dt.Columns.Add("Description");
            dt.Columns.Add("InvariantName");
            dt.Columns.Add("AssemblyQualifiedName");
            dt.Rows.Add(dataProviderName, dataProviderDescription, dataProvider, dataProviderType);

            //if (conn == "")
            //{
            //    string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
            //    assemblyFolder = assemblyFolder.Replace("\\Debug", "");
            //    assemblyFolder = assemblyFolder.Replace("\\bin", "");
            //    assemblyFolder = assemblyFolder.Replace("\\netcoreapp2.1", "");

            //    assemblyFolder = assemblyFolder.Replace("file:\\", "");
            //    string text = System.IO.File.ReadAllText(assemblyFolder + @"\appsettings.json");
            //    dynamic o = Newtonsoft.Json.JsonConvert.DeserializeObject<appSetting>(text);
            //    conn = o.Conn;

            //    if (conn == null)
            //    {
            //        conn = DbConnection;
            //    }
            //}
            //Modify the connections to suit
            //Comment any databases that should not be executed against
            DBDatabase mysql = DBDatabase.Create("MySQL"
                                                 , conn
                                                 , DbProvider, dt);

            this._database = mysql;
            this._database.HandleException += new DBExceptionHandler(database_HandleException);
            var il = conn.Split(';').Where(x => x.ToLower().IndexOf("initial") >= 0).ToList();

            if (il.Count > 0)
            {
                _Schema = il[0].ToLower().Replace("initial catalog=", "");
                _Schema = _Schema.Replace("database=", "");
            }
        }
Exemplo n.º 8
0
        public bool CheckConnection(out Exception failure)
        {
            bool success = false;

            failure = null;
            try
            {
                DBDatabase db = DBDatabase.Create(this.ConnectionString, this.ProviderName);

                //validate that we can get the properties and a schema provider
                DBDatabaseProperties    props = db.GetProperties();
                Schema.DBSchemaProvider prov  = db.GetSchemaProvider();
                Schema.DBSchemaMetaDataCollectionSet collections = prov.Collections;

                success = true;
            }
            catch (Exception ex)
            {
                success = false;
                failure = ex;
            }
            return(success);
        }
Exemplo n.º 9
0
        /* End SQL Server connections */

        /* MySql Connections
         * public const string DbConnection = "server=172.16.56.1;User Id=testaccount;Password=test;Persist Security Info=True;database=northwind;AllowUserVariables=true";
         * public const string DbProvider = "MySql.Data.MySqlClient";
         * /* End SQL Server connections */

        /* SQLite connections
         * public const string DbConnection = @"data source=C:\Development\DynaSQL\DynaSQLUnitTest.db;foreign keys=true;"; //we add the foreign keys=true here to enforce them
         * public const string DbProvider = "System.Data.SQLite";
         * /* End SQLite connections */

        /* MS Access connections
         * public const string DbConnection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Sample Databases\Northwind2007.accdb;Persist Security Info=False;";
         * public const string DbProvider = "System.Data.OleDb";
         * /* End MSAccess connections */

        #region private static DBDatabase CreateDb()

        /// <summary>
        /// Creates the database connection
        /// </summary>
        /// <returns></returns>
        private static DBDatabase ConnectDb()
        {
            return(DBDatabase.Create(DbConnection, DbProvider));
        }