microsoft / microsoft/sqlmanagementobjects
JobServer constructor shouldn't run a SQL query
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 143
- Forks
- 28
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
the JobServer class requires initializing its parent's Databases collection to construct itself:
internal JobServer(Server parentsrv, ObjectKeyBase key, SqlSmoState state) :
base(key, state)
{
// even though we called with the parent collection of the column, we will
// place the JobServer under the right collection
singletonParent = parentsrv as Server;
// WATCH OUT! we are setting the m_server value here, because JobServer does
// not live in a collection, but directly under the Database
SetServerObject( parentsrv.GetServerObject());
m_comparer = parentsrv.Databases["msdb"].StringComparer;
jobCategories = null;
alertCategories = null;
operatorCategories = null;
alertSystem = null;
alerts = null;
operators = null;
targetServers = null;
targetServerGroups = null;
jobs = null;
sharedSchedules = null;
}
- It shouldn't be making a SQL query of any kind in the constructor anyway
- Populating the databases collection is hugely expensive
- SqlSmoObject has a way to delay load StringComparer already that doesn't populate the collection, this object may just need a little refactoring of that method to support specifying msdb as the database to use for the query.
I found this by accident while trying to write a test for something else.
This code blows up because Databases["msdb"] doesn't exist:
var smoFilter = "[contains(@Name, 'SmoBaseline')]";
db.Parent.Databases.ClearAndInitialize($"[@Name='{Urn.EscapeString(db.Name)}']", Enumerable.Empty<string>());
db.Parent.Logins.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
db.Parent.LinkedServers.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
if (db.Parent.IsSupportedObject<JobServer>())
{
db.Parent.JobServer.Jobs.ClearAndInitialize(smoFilter, Enumerable.Empty<string>());
}
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comience por el constructor de JobServer mostrado en el issue e inspeccione cómo parentsrv.Databases["msdb"] obtiene StringComparer. Compare esto con la carga diferida existente de StringComparer en SqlSmoObject y, a continuación, use el escenario de prueba ClearAndInitialize proporcionado para verificar que construir JobServer no rellena Databases ni falla cuando msdb está ausente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, sql
- Área
- databases
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100