private static SourceTimetableData GetSourceTimetableData(string timetableConnectionString, int timeoutSecs) { SourceTimetableData result = null; var csb = new SqlConnectionStringBuilder(timetableConnectionString); var sql = "select timetable_name, version, guid from CT_CONFIG"; DatabaseUtils.GetSingleResult(timetableConnectionString, sql, timeoutSecs, r => { result = new SourceTimetableData { Name = (string)r["timetable_name"], SqlServerName = csb.DataSource, DatabaseName = csb.InitialCatalog, Identifier = (Guid)r["guid"], SchemaVersion = (int)r["version"], ConnectionString = timetableConnectionString }; }); return(result); }
/// <summary> /// registers the specified timetable in the admin database /// </summary> /// <param name="adminConnectionString"></param> /// <param name="timeoutSecs"></param> /// <param name="tt"></param> /// <returns> /// The id of the newly-inserted row /// </returns> private static int RegisterSourceTimetable(string adminConnectionString, int timeoutSecs, SourceTimetableData tt) { var sb = new SqlBuilder(); sb.AppendFormat( "insert into {0} (timetable_name, server_name, database_name, schema_version, guid)", DatabaseUtils.GetQualifiedTableName(ControlSchema.ControlSchemaName, ControlSchema.SrcTimetableName)); sb.Append("values (@N, @S, @D, @V, @G); select @@IDENTITY"); var p = new List <SqlParameter> { new SqlParameter("@N", tt.Name), new SqlParameter("@S", tt.SqlServerName), new SqlParameter("@D", tt.DatabaseName), new SqlParameter("@V", tt.SchemaVersion) }; var guidParam = new SqlParameter("@G", SqlDbType.UniqueIdentifier) { Value = tt.Identifier }; p.Add(guidParam); int result = Convert.ToInt32(DatabaseUtils.ExecuteScalar(adminConnectionString, sb.ToString(), timeoutSecs, p.ToArray())); return(result); }