Código sql:
Ver originalCREATE PROCEDURE [dbo].[Sp_CrearLogin]
(
@DOMAIN VARCHAR(100),
@HOST VARCHAR(100)
)
AS
BEGIN TRY
DECLARE @SQLString NVARCHAR(MAX)
SET @SQLString = N'CREATE LOGIN [' + UPPER(@DOMAIN) + '\' + @HOST + '] FROM WINDOWS';
EXECUTE SP_EXECUTESQL @SQLString
SET @SQLString = N'USE NOMBD;';
SET @SQLString =@SQLString + N'CREATE USER [' + UPPER(@DOMAIN) + '\' + @HOST + '] FOR LOGIN ' + '[' + UPPER(@DOMAIN) + '\' + @HOST + ']';
SET @SQLString =@SQLString + N' WITH DEFAULT_SCHEMA = NOMBD;'
EXECUTE SP_EXECUTESQL @SQLString
--¡¡¡¡¡¡¡SE DEBE CAMBIAR DB_OWNER POR OTRO ROL CON MENOS PERMISOS SOBRE EL SERVIDOR!!!!!
SET @SQLString = N'EXECUTE SP_ROLEMEMBER "db_owner", [' + UPPER(@DOMAIN) + '\' + @HOST + ']'
EXECUTE SP_EXECUTESQL @SQLString
END TRY
BEGIN CATCH
PRINT 'NUMERO DE ERROR: ' + CONVERT(VARCHAR,ERROR_NUMBER());
PRINT 'MENSAJE DE ERROR: ' + ERROR_MESSAGE();
END CATCH;