Exemplo n.º 1
0
	public static int RemoveConnector (CommonDataBase.DataBase DataBaseInstance, String TableName,
								String IDName, String IDToRemove)
		{
		if (String.IsNullOrEmpty (TableName))
			return 0;
		if (String.IsNullOrEmpty (IDName))
			return 0;
		if (String.IsNullOrEmpty (IDToRemove))
			return 0;
		DataSet ExistingConnectorDataSet = DataBaseInstance.GetCommonDataSet ("Select * from " + TableName
						+ " where " + IDName + " = '" + IDToRemove + "'");
		int ConnectionCounter = 0;
		foreach (DataRow RowToDelete in ExistingConnectorDataSet.Tables [TableName].Rows)
			{
			String DeleteCommand = "Delete from [" + TableName + "] where " + IDName  + " = '" + IDToRemove + "'";
			DataBaseInstance.RunSQLBatch (DeleteCommand);
			ConnectionCounter++;
			}
		return ConnectionCounter;
		}
Exemplo n.º 2
0
	public static void RemoveViaID (CommonDataBase.DataBase DataBaseInstance, String TableName,
								String IDName, String IDToRemove)
		{
		if (String.IsNullOrEmpty (TableName))
			return;
		if (String.IsNullOrEmpty (IDName))
			return;
		if (String.IsNullOrEmpty (IDToRemove))
			return;
		String DeleteCommand = "Delete from [" + TableName + "] where " + IDName + " = '" + IDToRemove + "'";
		DataBaseInstance.RunSQLBatch (DeleteCommand);
		}
Exemplo n.º 3
0
	public static void DropView (CommonDataBase.DataBase DataBaseInstance, String ViewName)
		{
		DataBaseInstance.RunSQLBatch (String.Format (m_DropViewTemplate, ViewName));
		}
Exemplo n.º 4
0
	public static void DropTable (CommonDataBase.DataBase DataBaseInstance, String TableName)
		{
		DataBaseInstance.RunSQLBatch (String.Format (m_DropTableTemplate, TableName));
		}
Exemplo n.º 5
0
	public static bool DetachDataBase (CommonDataBase.DataBase DataBaseInstance, String DataBaseName)
		{
		DataSet DataBases = DataBaseInstance.GetCommonDataSet ("Select Name from sys.databases");
		bool DetachIsNecessary = false;
		foreach (DataRow DataBaseRow in DataBases.Tables [0].Rows)
			{
			if (String.Compare (DataBaseName, DataBaseRow ["name"].ToString (), true) == 0)
				{
				DetachIsNecessary = true;
				break;
				}
			}
		if (DetachIsNecessary)
			{
			String DetachCommand = String.Format (m_DetachDataBaseTemplate, DataBaseName);
			DataBaseInstance.RunSQLBatch (DetachCommand);
			return true;
			}

		return false;
		}
Exemplo n.º 6
0
	public static void AttachDataBase (CommonDataBase.DataBase DataBaseInstance, String DataBaseName,
				String DataBaseFileName)
		{
		DetachDataBase (DataBaseInstance, DataBaseName);
		String AttachCommand = String.Format (m_AttachDataBaseTemplate, DataBaseName, DataBaseFileName,
											  DataBaseFileName.Replace (".mdf", ".ldf"));
		DataBaseInstance.RunSQLBatch (AttachCommand);
		}
Exemplo n.º 7
0
	public static bool CreateRuntimeTables (ref CommonDataBase.DataBase DataBaseInstance,
						String DataBaseName, String [] TableCreationCommands,
						CommonDataBase.StatusCallBack StatusCallBackHandler)
		{
		if (StatusCallBackHandler != null)
			StatusCallBackHandler (220, "CommonBasics.CreateRuntimeTables Started");
		foreach (String TableCreationCommand in TableCreationCommands)
			{
			try
				{
				DataBaseInstance.RunSQLBatch (String.Format (TableCreationCommand,
							  DataBaseName));
				}
			catch (Exception Excp)
				{
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (999, TableCreationCommand);
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (999, "CommonBasics.CreateRuntimeTables\r\n" + Excp.ToString());
				return false;
				}
			}
		if (StatusCallBackHandler != null)
			StatusCallBackHandler (230, "CommonBasics.CreateRuntimeTables Successfully ended");
		return true;
		}
Exemplo n.º 8
0
		private static bool CreateRuntimeDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName,
					String DataBaseFileName, CommonDataBase.StatusCallBack StatusCallBackHandler)
		{
		String PureFileName = Path.GetFileNameWithoutExtension (DataBaseFileName);
		String DataBaseDirectory = Path.GetDirectoryName (DataBaseFileName);
		if (!Directory.Exists (DataBaseDirectory))
			{
			Directory.CreateDirectory (DataBaseDirectory);
			}
		DetachDataBase (DataBaseInstance, DataBaseName);
		String CreationCommand;
		if (String.Compare (Path.GetExtension (DataBaseFileName), ".mdf", true) == 0)
			{
			CreationCommand = String.Format (m_CreateDataBaseTemplate,
					DataBaseName, DataBaseFileName, DataBaseFileName.Replace (".mdf", ".ldf"));
			try
				{
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (200, PureFileName + " Detach Started");
				DataBaseInstance.RunSQLBatch (CreationCommand);
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (210, PureFileName + " Successfully ended");
				}
			catch (Exception Excp)
				{
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (999, CreationCommand);
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (999, "CommonBasics.CreateRuntimeDataBase\r\n" + Excp.ToString());
				return false;
				}
			return true;
			}
		else
			{
			//File.Create (DataBaseFileName);
			return true;
			}
		try
			{
			if (StatusCallBackHandler != null)
				StatusCallBackHandler (200, PureFileName + " Creation Started");
			DataBaseInstance.RunSQLBatch (CreationCommand);
			if (StatusCallBackHandler != null)
				StatusCallBackHandler (210, PureFileName + " Successfully ended");
			}
		catch (Exception Excp)
			{
			if (StatusCallBackHandler != null)
				StatusCallBackHandler (999, CreationCommand);
			if (StatusCallBackHandler != null)
				StatusCallBackHandler (999, "CommonBasics.CreateRuntimeDataBase\r\n" + Excp.ToString());
			return false;
			}
		return true;
		}
Exemplo n.º 9
0
		private static bool DeleteRuntimeDataBase (ref CommonDataBase.DataBase DataBaseInstance, String DataBaseName,
						String DataBaseFileName, CommonDataBase.StatusCallBack StatusCallBackHandler)
			{
			String DetachCommand = String.Format (m_DetachDataBaseTemplate, DataBaseName);
			try
				{
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (200, DataBaseName + " Detach Started");
				DataBaseInstance.RunSQLBatch (DetachCommand);
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (210, DataBaseName + " Completely detached");
				}
			catch (Exception Excp)
				{
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (998, DetachCommand);
				if (StatusCallBackHandler != null)
					StatusCallBackHandler (999, "CommonBasics.DeleteRuntimeDataBase\r\n" + Excp.ToString());
				return false;
				}
			if ((SecureFileDelete (DataBaseFileName, StatusCallBackHandler) == false)
				|| (SecureFileDelete (DataBaseFileName.Replace (".mdf", ".ldf"), StatusCallBackHandler) == false))
				if (StatusCallBackHandler != null)
					{
					StatusCallBackHandler (999, "Ein oder beide Datenbanken Files\r\n(\"" + DataBaseFileName + "\",\r\n\""
						+ DataBaseFileName.Replace (".mdf", ".ldf") + "\")\r\nkonnte(n) nicht gelöscht werden");
					return false;
					}
			return true;
			}