/// <summary>Verifies 'tablename' is not among standard system tables</summary> /// <param name="tablename"></param> /// <returns></returns> bool IsValidTablename(string tablename) { tablename = VEObjectName.Parse(tablename).ObjectName; return(tablename.ToLower().IndexOf("sys") != 0 && !InvalidTableNames.Contains(tablename.ToUpper())); }
/// <summary> Executes a stored procedure to copy a table from one database.schema to another database.schema on the same server. /// <para>Source and target objects must have been initialized using .SetSource(...) and .SetTarget(...)</para> /// <para>Sets 'copied' is set to the number of records copied during this iteration and</para> /// <para>'targetTotal' to the total count on the target table at the end of this iteration</para> /// <para>Note: This operation may timeout. Call .SQLHandler() before calling this method and check .HasErrors to continue the operation. </para> /// </summary> /// <param name="table"></param> /// <param name="copied"></param> /// <param name="targetTotal"></param> /// <returns></returns> bool CopyServerTables(string table, ref int copied, ref int targetTotal) { VEObjectName veName = new VEObjectName(table); bool okay = SourceDatabase != TargetDatabase || SourceSchema != TargetSchema; if (!okay) { message = string.Format("VEAdmin..CopyServerTables: Source and Target tables must differ - {0}.{1}.{2}", SourceDatabase, SourceSchema, veName.TableName); } else { try { VEDataParameters parameters = CopyTableParameters; if (okay = parameters != null && parameters.Count >= 5) { parameters["@sourceDatabase"].Value = SourceDatabase; parameters["@sourceOwner"].Value = SourceSchema; parameters["@targetDatabase"].Value = TargetDatabase; parameters["@targetOwner"].Value = TargetSchema; parameters["@tableName"].Value = veName.TableName; if (targetCmd.ExecuteStoredProcedure(parameters) < 0) { SQLHandler.Message = (string)parameters["@message"].Value; } copied = (int)parameters["@copied"].Value; targetTotal = (int)parameters["@targetTotal"].Value; } else { message += string.Format("\r\nVEDatabaseAdmin.CopyServerTables: An error occurred retrieving parameters for procedure '{0}' on {1}", CopyTableProcedure, targetCmd.DataControl.Connection); copied = targetTotal = -1; } } catch (Exception e) { // // Don't report timeout exceptions // if (e.Message.ToLower().IndexOf("timeout") < 0) { Error(string.Format("VEDataAdmin.CopyServerTables: {0}Table: Trying to Copy a Table by Stored Procedure - [{1}].{2}\r\n", copyModifier, targetObject.ServerID, table), e); copyLoop = 999; copied = -999; } } } if (!okay) { Error(SQLHandler.Errors); } return(okay); }