Beispiel #1
0
        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <param name="connectionstring"></param>
        /// <remarks>连接同时将启动所有异步线程</remarks>
        public void Connect(string connectionstring = null)
        {
            if (connectionstring != null)
            {
                _ConnectionString = connectionstring;
            }

            if (Status == DataBaseStatus.Stoped)
            {
                //MessageBox.Show("数据库已停止");
                return;
            }
            if (Status == DataBaseStatus.Started)
            {
                //MessageBox.Show( "已经连接" );
                return;
            }

            Status = DataBaseStatus.Started;

            if (_ConnectionString == null)
            {
                //MessageBox.Show( "数据库未指定连接字符串" );
                return;
            }

            _Provider.Connect(_ConnectionString);
            _Provider.Connect(_ConnectionString);
        }
Beispiel #2
0
 public IQueueConfiguration GetQueueConfiguration(string queueIdentifier)
 {
     using (var db = _dbProvider.Connect(_connectionStringConfig.TransactionProcessing))
     {
         var ident = DebugModeStringHandler.UnmakeDebugIdentifierValue(queueIdentifier);
         return(_dbProvider.Select <PocoQueueConfiguration>(db, x => x.QueueIdentifier == ident).FirstOrDefault());
     }
 }
Beispiel #3
0
        private void CallbackRefreshTables(AsyncCallbackState callbackState)
        {
            var             data           = (Tuple <IDBProvider, IConnectionInfo>)callbackState.State;
            IDBProvider     dbProvider     = data.Item1;
            IConnectionInfo connectionInfo = data.Item2;

            if (dbProvider.IsConnected)
            {
                dbProvider.Disconnect();
            }

            bool connectResult = dbProvider.Connect(connectionInfo);

            if (connectResult)
            {
                Server   server       = new Server(connectionInfo.ServerName);
                Database database     = new Database(connectionInfo.DatabaseName, server);
                bool     refresResult = dbProvider.Refresh(database, LoadingMode.RecursiveAllLevels);

                if (refresResult)
                {
                    callbackState.InvokeOnUI(delegate(object state)
                    {
                        Database db = (Database)state;

                        PopulateTables(db);
                    }, database);
                }
            }
        }
Beispiel #4
0
        public override void EnterPage(PageDirection enterDirection)
        {
            if (enterDirection == PageDirection.Next)
            {
                Tuple <IDBProvider, IConnectionInfo> selectedDatabase = this.wizardOwner.SelectedDB;

                IDBProvider dbProvider = selectedDatabase.Item1;
                if (dbProvider.IsConnected)
                {
                    dbProvider.Disconnect();
                }

                bool connectResult = dbProvider.Connect(selectedDatabase.Item2);
                if (connectResult)
                {
                    RefreshTables();
                }
            }
        }
Beispiel #5
0
        public void Test_Load_Xtensive_DBProvider()
        {
            TestLogger       logger         = new TestLogger("Test_Load_Xtensive_DBProvider");
            DBProviderModule xtensiveModule = new DBProviderModule();

            //xtensiveModule.mock_implementationFileFolder = @"c:\Projects\Private\xp-dev.com\doemd\Sources\DBProviders\DBProvider.Xtensive.Implementation\bin\Debug\";
            xtensiveModule.mock_implementationFileFolder = @"d:\Projects\Private\xp.dev.com\doemd\Sources\DBProviders\DBProvider.Xtensive.Implementation\bin\Debug\";
            bool result = xtensiveModule.Initialize();

            try
            {
                Assert.IsTrue(result, "Initialization of Xtensive's 'DBProviderModule' failed. Last errors: " +
                              string.Join(Environment.NewLine, xtensiveModule.LastErrors.Select(ex => ex.Message)));

                Assert.IsNotNull(xtensiveModule.Providers, "Xtensive's 'DBProviderModule' returns null list of providers.");
                Assert.AreNotEqual(xtensiveModule.Providers.Length, 0, "Xtensive's 'DBProviderModule' returns zero providers.");

                IDBProvider dbProvider = xtensiveModule.Providers.First();

                var connectionInfo = dbProvider.ConnectionInfoProvider.CreateInfo(new StorageEngine("sqlserver"), "sa", "halo", "localhost", "TheConsole");
                try
                {
                    bool connected = dbProvider.Connect(connectionInfo);
                    Assert.IsTrue(connected, "Connection to sql server failed.");

                    ServerCollection servers = dbProvider.GetAllServers(LoadingMode.TopLevel);
                    Assert.IsNotNull(servers, "dbProvider.GetAllServers returns null");
                    Assert.AreNotEqual(servers.Count, 0, "dbProvider.GetAllServers returns empty list of servers.");

                    logger.Log("Provider '{0}' retrieved {1} servers", dbProvider.Name, servers.Count);
                    foreach (var server in servers)
                    {
                        logger.Log("\tserver '{0}'", server.Name);
                    }

                    Server serverLocalhost = servers["localhost"];
                    bool   refreshResult   = dbProvider.Refresh(serverLocalhost, LoadingMode.TopLevel);
                    Assert.IsTrue(refreshResult, "Refreshing details about server 'localhost' failed");

                    logger.Log("\tProvider '{0}' refreshed {1} databases for server '{2}'", dbProvider.Name, serverLocalhost.Databases.Count, serverLocalhost.Name);
                    foreach (var database in serverLocalhost.Databases)
                    {
                        logger.Log("\t\tdatabase '{0}'", database.Name);
                        refreshResult = dbProvider.Refresh(database, LoadingMode.TopLevel);
                        Assert.IsTrue(refreshResult, string.Format("Refreshing details about database '{0}' failed", database.Name));

                        logger.Log("\t\tProvider '{0}' refreshed {1} schemas for database '{2}'", dbProvider.Name, database.Schemas.Count, database.Name);
                        foreach (var schema in database.Schemas)
                        {
                            logger.Log("\t\t\tschema '{0}'", schema.Name);
                        }
                    }
                }
                finally
                {
                    dbProvider.Disconnect();
                    Assert.IsFalse(dbProvider.IsConnected, "DbProvider is still connected after 'Disconnect' method called.");
                }
            }
            finally
            {
                xtensiveModule.Deinitialize();
            }
        }