lunes, 6 de febrero de 2012

Agente XP's deshabilitado

El Agente no es capaz de arrancar; en SSMS, en el Object Browser aparece justo al lado de él 'Agente XPs diabled'.






El par de veces que me ha pasado,  el problema había sido que alguien había cambiado las cuentas del agente desde sel Server Manager de Windows, no desde el configuration Manager de SQL Server.
Simplemente abrir este último, cambiar la cuenta a su original, aplicar, volver a poner la nueva, aplicar y el agente arrancará


Lo de usar sp_configure y cambiar el status de Xps a 1 no tiene sentdio, ya que si el agente no arranca, el Agente XP  seguirá deshabilitado

Si esta solucción no os sirve,tratar de arrancar el agente desde línea de comando con el parámetro -v para que os salve la salida. Puede darse el caso que el sqlagent.out se encuentre en una ruta diferente.

ah, y aseguraros que la cuenta tiene los permisos correctos si no es sysadmin,

miércoles, 25 de enero de 2012

Migrar logins de dominio...

...o cambios de login sin cambio de dominio:

 ALTER LOGIN [dominio\login WITH NAME=[nuevo dominio\login]

martes, 9 de agosto de 2011

Error al reorganizar índices en plan de mantenimiento

En el log del trabajo podemos encontrar algo así como el siguiente error:

Failed:(-1073548784) Executing the query "ALTER INDEX [PK_XXXX] ON [dbo].[XXXXX] REOR..." failed with the following error: "The index "PK_XXXX" (partition 1) on table "XXXXX" cannot be reorganized because page level locking is disabled.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.


La causa es que la opción de "Page Locks", requerida para efectuar la reorganización o la recreación de índices, ha sido deshabilitada. Al parecer esto suele ocurrir cuando se migra una bbdd de SQL 2005 al 2008; por alguna razón  en algunos índices se deshabilita esta opción.



Puede arreglarse:

>ALTER INDEX [PK_XXXX ON [dbo].[XXXXXX] SET (

ALLOW_PAGE_LOCKS = ON

) ;

Con Management Studio,  botón derecho en el índice en cuestión, propiedades, opciones y ahí marcáis la opci´´on de permitir  "page lock"





viernes, 4 de marzo de 2011

xp_cmdshell: comprobar estado antes de ejecutarla

Por razones obvias, es mejor tener xp_cmdshell deshabilitado y habilitarlo sólo cuando es necesario. Para evitar males mayores, igual es recomendable antes de reconfigurar verificar su estado, y una vez ejecutado nuestro script dejarlo como estaba.

Unas pequeñas líneas pueden ahorrarnos algún que otro lío (experiencia personal esta semana :-)

Podéis crear una variable o una pequeña tabla temporal:
-- xp_cmdshell configuration --

CREATE TABLE #config (val int)

INSERT INTO #config SELECT convert(int, vlaue_in_use)
FROM master.sys.configurations WHERE name= 'xp_cmdshell'


IF (SELECT val FROM #config)= 0

-- enable xp_cmdshell and lock it again after completed the script

BEGIN
 EXEC sp_configure 'show advanced options', 1
 RECONFIGURE
 EXEC sp_configure 'xp_cmdshell',1
 RECONFIGURE

END

--AQUI EL CÓDIGO


-- set xp_cmdshell as its previous state if it was changed

IF (SELECT val FROM  #config) = 0

BEGIN
 EXEC sp_configure 'show advanced options', 1
 RECONFIGURE
 EXEC sp_configure 'xp_cmdshell',0
 RECONFIGURE
END


DROP TABLE #config

Lo mismo para OLE Automatation

lunes, 21 de febrero de 2011

Renombrar instancia SQL Server

Por defecto (nombre del servidor:


sp_dropserver NombreServidorAntiguo
GO
sp_addserver NuevoNombreServidor, local
GO


Instancia

sp_dropserver NombreServfidorAntiguo\NombreInstanciaAntigua
GO
sp_addserver NombreservidorNuevo\NombreInstanciaNueva, local
GO


Clúster:

Usar el Adminitrador de Clúster:


Poner 'offline' SQL Server y volver a ponerlo de nuevo en linea.


En todos los casos, una vez cambiado el nombre verificar que haya funcionado

Select @@servername

Recordar que habrá que manualmente modificar los paquetes SSIS para actualizar conel nuevo nombre del servidor/instancia

Ejemplo de error:

  Description: Failed to acquire connection "Local server connection". Connection may not be configured correctly or you may not have the right permissions on this connection.  End Error  Warning: 2011-02-21 10:35:27.16     Code: 0x80019002     Source: OnPreExecute 


Hay un script que facilita las cosas. Está publicado en MSDN aunque ellos no lo crearan y se curen en salud diciendo que no admiten responsabilidades. funcionar funciona bien



use msdb
DECLARE @oldservername as varchar(max)
SET @oldservername='\'

-- set the new server name to the current server name
declare @newservername as varchar(max)
set @newservername=@@servername

declare @xml as varchar(max)
declare @packagedata as varbinary(max)
-- get all the plans that have the old server name in their connection string
DECLARE PlansToFix Cursor
FOR
SELECT    id
FROM         sysdtspackages90
WHERE     (CAST(CAST(packagedata AS varbinary(MAX)) AS varchar(MAX)) LIKE '%server=''' + @oldservername + '%')

OPEN PlansToFix


declare @planid uniqueidentifier
fetch next from PlansToFix into @planid
while (@@fetch_status<>-1)  -- for each plan

begin
if (@@fetch_status<>-2)
begin
select @xml=cast(cast(packagedata as varbinary(max)) as varchar(max)) from sysdtspackages90 where id= @planid  -- get the plan's xml converted to an xml string

declare @planname varchar(max)
select @planname=[name] from  sysdtspackages90 where id= @planid  -- get the plan name
print 'Changing ' + @planname + ' server from ' + @oldservername + ' to ' + @newservername  -- print out what change is happening

set @xml=replace(@xml,'server=''' + @oldservername + '''','server=''' + @newservername +'''')  -- replace the old server name with the new server name in the connection string
select @packagedata=cast(@xml as varbinary(max))  -- convert the xml back to binary
UPDATE    sysdtspackages90 SET packagedata = @packagedata WHERE (id= @planid)  -- update the plan

end
fetch next from PlansToFix into @planid  -- get the next plan

end

close PlansToFix
deallocate PlansToFix

 Más información:

cómo renombrar una instancia de SQL (inglés) 2008R2

Cómo renombrar una instancia 2005 (incluye scipts par amodificar SSIS)
Cómo renombrar un clúster