protected OracleConnectionProvider GetConnectionProvider()
        {
            var p = new OracleConnectionProvider();

            p.SetConnectionString(_connectionString);
            return(p);
        }
Пример #2
0
        public void Basic_retrival_of_tables()
        {
            var connectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;

            var provider = new OracleConnectionProvider();

            provider.SetConnectionString(connectionString);

            var connectionProvider = provider;
            var schemaProvider     = new OracleSchemaProvider(connectionProvider, new CustomSchemaConfiguration());
            var tables             = schemaProvider.GetTables().ToList();

            Assert.Contains("REGIONS", tables.Select(t => t.ActualName).ToList());
            Assert.Contains("DEPARTMENTS", tables.Select(t => t.ActualName).ToList());
            Assert.Contains("EMPLOYEES", tables.Select(t => t.ActualName).ToList());
            Assert.Contains("JOB_HISTORY", tables.Select(t => t.ActualName).ToList());
            Assert.Contains("JOBS", tables.Select(t => t.ActualName).ToList());
            Assert.Contains("LOCATIONS", tables.Select(t => t.ActualName).ToList());
        }
Пример #3
0
        /// <summary>
        /// 尝试根据配置文件中在appSettings节下指定的设置构造数据库连接字符串。
        /// 若失败则尝试获取connectionStrings节下指定的第一个连接字符串。
        /// </summary>
        /// <returns>构造或获取到的数据库连接字符串</returns>
        public static string GetConnectionString()
        {
            try
            {
                AppSettingsReader config = new AppSettingsReader();
                string            serverType, server, database, user, password;
                serverType = ((string)(config.GetValue("ServerType", typeof(string))));
                server     = ((string)(config.GetValue("Server", typeof(string))));
                database   = ((string)(config.GetValue("Database", typeof(string))));
                user       = ((string)(config.GetValue("User", typeof(string))));
                password   = ((string)(config.GetValue("Password", typeof(string))));

                switch (serverType.ToUpper())
                {
                case "ACCESS":
                    return(AccessConnectionProvider.GetConnectionString(database, user, password));

                case "MSSQL":
                    return(MSSqlConnectionProvider.GetConnectionString(server, user, password, database));

                case "MYSQL":
                    return(MySqlConnectionProvider.GetConnectionString(server, user, password, database));

                case "ORACLE":
                    return(OracleConnectionProvider.GetConnectionString(server, user, password));

                // ... generate connection strings for other providers, e.g. Firebird, etc.
                default:
                    return(ConfigurationManager.ConnectionStrings[0].ToString());
                }
            }
            catch
            {
                return(ConfigurationManager.ConnectionStrings[0].ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Подключение к БД.
        /// </summary>
        private void Connect()
        {
            switch (DataBaseType)
            {
            case SQLType.Access:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.Access2007:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);

                    //string connctionString = string.Format(@"Data Source={0};Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=qwe+ASDFG", Server);
                    //XpoDefault.DataLayer = XpoDefault.GetDataLayer(connctionString, AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSqlCE:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MySQL:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    MySqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                    AutoCreateOption);
                break;

            case SQLType.Oracle:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.Firebird:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PostgreSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.SQLite:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.VistaDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PervasiveSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.DB2:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.NexusDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            default:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    AccessConnectionProvider.GetConnectionString(DataBase),
                    AutoCreateOption.DatabaseAndSchema);
                break;
            }
        }
 public OracleSchemaProvider(OracleConnectionProvider connectionProvider)
 {
     _sqlReflection = new SqlReflection(connectionProvider);
 }
 protected OracleConnectionProvider GetConnectionProvider()
 {
     var p = new OracleConnectionProvider();
     p.SetConnectionString(_connectionString);
     return p;
 }
 public OracleSchemaProvider(OracleConnectionProvider connectionProvider)
 {
     _sqlReflection = new SqlReflection(connectionProvider);
 }
Пример #8
0
        static void Main()
        {
            try
            {
                bool bCreate;
                System.Threading.Mutex mutex = new System.Threading.Mutex(false, "SINGILE_INSTANCE_MUTEX", out bCreate);

                if (!bCreate)
                {
                    MessageBox.Show("程序已经启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Application.Exit();
                    return;
                }

                //设置应用程序处理异常方式:ThreadException处理
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                #region 应用程序的主入口点
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                BonusSkins.Register();
                SkinManager.EnableFormSkins();
                UserLookAndFeel.Default.SetSkinStyle("DevExpress Style");

                ///// 连接数据库 //////
                string ConnectionString = OracleConnectionProvider.GetConnectionString("orcl", "lime", "bestunion");
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(ConnectionString, AutoCreateOption.DatabaseAndSchema);
                SqlHelper.ConnectDb();

                ///// 检查版本  ///////
                //string curNewestVersion = Tools.getNewVersion();
                //if (string.Compare(curNewestVersion, AppInfo.AppVersion) > 0)
                //{
                //	MessageBox.Show("服务器发现更新的版本!系统需要升级", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //	Tools.DownloadNew(curNewestVersion);
                //	SqlAssist.DisConnect();

                //	//启动升级拷贝 //////
                //	try
                //	{
                //		Process.Start("Upgrade.exe", curNewestVersion);
                //	}
                //	catch (Exception e)
                //	{
                //		LogUtils.Error(e.Message);
                //	}

                //	Application.Exit();
                //	return;
                //}



                ///// 检查 工作站是否进行登记
                //Envior.WORKSTATIONID = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath).AppSettings.Settings["workstationID"].Value.ToString();
                //string hostname = string.Empty;
                //string ipaddress = string.Empty;
                //Tools.GetIpAddress(out hostname, out ipaddress);
                //if (!string.IsNullOrEmpty(Envior.WORKSTATIONID))
                //{
                //	switch (AppAction.WorkStationIsRegistered(Envior.WORKSTATIONID, hostname, ipaddress))
                //	{
                //		case 0:  //未登记
                //			MessageBox.Show("此工作站尚未登记!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //			Application.Exit();
                //			return;
                //		case 2:  //主机名不符
                //			MessageBox.Show("此工作站【计算机名称】与登记不符!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //			Application.Exit();
                //			return;
                //		case 3:  //ip地址不符
                //			MessageBox.Show("此工作站【IP地址】与登记不符!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //			Application.Exit();
                //			return;
                //		default:
                //			break;
                //	}
                //}
                //else
                //{
                //	MessageBox.Show("未设置工作站ID!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //	Application.Exit();
                //	return;
                //}

                Application.Run(new Frm_main());
                #endregion
            }
            catch (Exception ex)
            {
                string str = GetExceptionMsg(ex, string.Empty);
                LogUtils.Error(str);
                MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }