Пример #1
0
        /// <summary>
        /// 检测链接
        /// </summary>
        public static bool CheckDbConnection()
        {
            if (!Global.IsConnection)
            {
                ConnectionEntity    conn   = Global.GetProjectConnection();
                DbConnectionOptions entity = new DbConnectionOptions();
                WSH.CodeBuilder.DispatchServers.DataBaseType dbType = conn.ConnectionType;
                WSH.Common.DataBaseType databaseType = WSH.Common.DataBaseType.SqlServer;
                switch (dbType)
                {
                case WSH.CodeBuilder.DispatchServers.DataBaseType.MySql:
                    databaseType = WSH.Common.DataBaseType.MySql;
                    entity       = new DbConnectionOptions()
                    {
                        ConnectionString = conn.ConnectionString
                    };
                    break;

                case WSH.CodeBuilder.DispatchServers.DataBaseType.Access:
                    databaseType = WSH.Common.DataBaseType.Access;
                    entity       = new DbConnectionOptions()
                    {
                        ConnectionString = conn.ConnectionString
                    };
                    break;

                case WSH.CodeBuilder.DispatchServers.DataBaseType.Oracle:
                    databaseType = WSH.Common.DataBaseType.Oracle;
                    entity       = new DbConnectionOptions()
                    {
                        ConnectionString = conn.ConnectionString
                    };
                    break;

                case WSH.CodeBuilder.DispatchServers.DataBaseType.SqlServer:
                    databaseType = WSH.Common.DataBaseType.SqlServer;
                    entity       = new DbConnectionOptions()
                    {
                        ConnectionString = conn.ConnectionString
                    };
                    break;
                }
                Result result = DbConnectionManager.Connection(databaseType, entity);
                if (result.IsSuccess)
                {
                    Global.ConnectionString = result.Msg;
                    return(true);
                }
                return(false);
            }
            return(true);
        }