CheckDatabase() публичный Метод

Check for Availability
public CheckDatabase ( ) : bool
Результат bool
Пример #1
0
		public void CreateEntrys(string connection, string outputPath, string database)
		{
			TargetDir = outputPath;
			Manager = new DbAccessLayer(DbAccessType.MsSql, connection);
			bool checkDatabase;
			try
			{
				checkDatabase = Manager.CheckDatabase();
			}
			catch (Exception)
			{
				checkDatabase = false;
			}

			if (!checkDatabase)
			{
				throw new Exception("Database not accessible. Maybe wrong Connection or no Selected Database?");
			}
			var databaseName = string.IsNullOrEmpty(Manager.Database.DatabaseName) ? database : Manager.Database.DatabaseName;
			if (string.IsNullOrEmpty(databaseName))
			{
				throw new Exception("Database not exists. Maybe wrong Connection or no Selected Database?");
			}
			Console.WriteLine("Connection OK ... Reading Server Version ...");

			SqlVersion = Manager.RunPrimetivSelect<string>("SELECT SERVERPROPERTY('productversion')").FirstOrDefault();

			Console.WriteLine("Server version is {0}", SqlVersion);

			Console.WriteLine("Reading Tables from {0} ...", databaseName);

			Tables = Manager.Select<TableInformations>().Select(s => new TableInfoModel(s, databaseName, Manager)).ToList();
			Views = Manager.Select<ViewInformation>().Select(s => new TableInfoModel(s, databaseName, Manager)).ToList();
			StoredProcs = Manager.Select<StoredProcedureInformation>().Select(s => new StoredPrcInfoModel(s)).ToList();

			Console.WriteLine("Found {0} Tables, {1} Views, {2} Procedures ... select a Table to see Options or start an Action", Tables.Count(), Views.Count(), StoredProcs.Count());
			Enums = new List<Dictionary<int, string>>();
			RenderMenu();
		}
		public void CreateEntrys(string connection, string outputPath, string database)
		{
			Status = "Try to connect";
			//Data Source=(LocalDb)\ProjectsV12;Integrated Security=True;Database=TestDB;
			IsEnumeratingDatabase = true;
			TargetDir = outputPath;
			Manager = new DbAccessLayer(DbAccessType.MsSql, connection);
			DbConfig.EnableGlobalThreadSafety = true;
			try
			{
				Connected = Manager.CheckDatabase();
			}
			catch (Exception)
			{
				IsEnumeratingDatabase = false;
				Connected = false;
			}

			if (!Connected)
			{
				IsEnumeratingDatabase = false;
				Status = ("Database not accessible. Maybe wrong Connection or no Selected Database?");
				return;
			}
			var databaseName = string.IsNullOrEmpty(Manager.Database.DatabaseName) ? database : Manager.Database.DatabaseName;
			if (string.IsNullOrEmpty(databaseName))
			{
				IsEnumeratingDatabase = false;
				Status = ("Database not exists. Maybe wrong Connection or no Selected Database?");
				Connected = false;
				return;
			}
			Status = "Connection OK ... Reading Server Version ...";

			SqlVersion = Manager.RunPrimetivSelect<string>("SELECT SERVERPROPERTY('productversion')").FirstOrDefault();
			Status = "Reading Tables";

			int counter = 3;
			base.SimpleWorkWithSyncContinue(() =>
			{
				return
					new DbAccessLayer(DbAccessType.MsSql, connection).Select<TableInformations>()
						.Select(s => new TableInfoModel(s, databaseName, new DbAccessLayer(DbAccessType.MsSql, connection)))
						.Select(s => new TableInfoViewModel(s, this))
						.ToList();
			}, dbInfo =>
			{
				foreach (var source in dbInfo)
				{
					if (Tables.All(f => f.Info.TableName != source.Info.TableName))
						Tables.Add(source);
				}
				this.SelectedTable = Tables.FirstOrDefault();
				counter--;
				if (counter == 0)
				{
					IsEnumeratingDatabase = false;
					Status = "Done";
				}
			});
			base.SimpleWorkWithSyncContinue(() =>
			{
				return
					new DbAccessLayer(DbAccessType.MsSql, connection)
					.Select<ViewInformation>()
					.Select(s => new TableInfoModel(s, databaseName, new DbAccessLayer(DbAccessType.MsSql, connection)))
					.ToList();
			}, dbInfo =>
			{
				foreach (var source in dbInfo)
				{
					if (Views.All(f => f.Info.TableName != source.Info.TableName))
						Views.Add(source);
				}

				counter--;
				if (counter == 0)
				{
					IsEnumeratingDatabase = false;
					Status = "Done";
				}
			});
		}