12 November 2018

Install Linux on Mac with broken internal CD/DVD

I could finally install Linux Mint XFCE on an iMac 20" 2006 (iMac 5,1) with broken internal CD/DVD reader.

Here is what you need:

1. rEFInd ISO image (mine was refind-cd-0.8.7.iso);

2. one USB drive stick;

3. an external USB CD/DVD device;

4. Mattgadient’s Linux Mint DVD iso image (BTW, thanks to Matt Gadient);

5. a blank DVD media;

6. USB keyboard and mouse.

7. not mandatory, an Internet connection with an Ethernet cable or a tethering cell phone connection via USB cable.


Proceed as follows:

a. write the rEFInd onto the USB stick (I used “USB Image Writer” Linux application, which makes a bootable USB stick);

b. burn the Linux iso image onto the blank DVD;

c. attach both the USB stick, the USB DVD reader and the USB keyboard to the USB ports of the Mac;

d. boot the Mac;

e. after a while, the boot screen of rEFInd will appear. Select the DVD media as your boot device;

f. be patient: give the Linux installer the time it needs;

g. start the installation process and be *very* patient: the complete startup will take some time. Roll a spliff!;

h. choose the standard installation (Mint will install the Linux partition on /dev/disk0s2);

i. after the installation is finished, reboot your system;

l. when the rEFInd boot screen appears, choose your internal HD as boot device.


It’s done!

Now you have to activate the WiFi hardware. Open “Driver Manager” application of your brand new installed Linux. You’ll see that the network controller Broadcom Limited BCM4321 is disabled by defaut. Activate it by clicking the checkbox… Done!

As for the iSight webcam, I could make it work perfectly following the instructions here:
http://www.howtoeverything.net/linux/hardware/making-isight-work-ubuntu-linux-mint-and-skype

To reduce the startup grey screen time, the instruction you find above, right in this page, are ok. Remember to verify your Linux partition with the terminal command “diskutil list”. In my case the fix command was:

bless –device /dev/disk0s2 –legacy –setBoot –verbose



… One more thing… In order for this method to work, you need to format your Mac’s internal Hard Drive, first. In other words, the internal HD must be empty, with no OS at all, otherwise rEFInd won’t see the installer DVD. Strange, but true.



An extra trick that could be useful: boot the installer in safe mode.



Via.

09 November 2018

Generate rows with random data in SQL Server

IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
 DROP TABLE #tmp


SELECT   TOP 1000 
    IDENTITY(INT, 1, 3) AS ID
  , RAND(CHECKSUM(NEWID())) * 30000 + CAST('1945' AS DATETIME) AS randomDate
  , ABS(CHECKSUM(NEWID())) AS randomBigInt
  , (ABS(CHECKSUM(NEWID())) % 100) + 1 AS randomSmallInt
  , RAND(CHECKSUM(NEWID())) * 100 AS randomSmallDec
  , RAND(CHECKSUM(NEWID())) AS randomTinyDec
  , RAND(CHECKSUM(NEWID())) * 100000 AS randomBigDec
  , CONVERT(VARCHAR(6),CONVERT(MONEY,RAND(CHECKSUM(NEWID())) * 100),0) AS randomMoney
INTO #tmp
FROM master.dbo.syscolumns sc1, master.dbo.syscolumns sc2, master.dbo.syscolumns sc3


SELECT *
FROM #tmp

31 October 2018

Extracting a .NET Assembly from SQL Server 2005

-------------------------------------------------------------------------------
-- TURN Ole Automation Procedures ON
-------------------------------------------------------------------------------
EXEC sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
EXEC sp_configure 'Ole Automation Procedures', 1;  
GO  
RECONFIGURE;  
GO  


PRINT ''
PRINT ''



-------------------------------------------------------------------------------
-- PARAMTERS
-------------------------------------------------------------------------------
DECLARE @rootPath nvarchar(100); SET @rootPath = 'C:\MyAssembly\'




-------------------------------------------------------------------------------
-- EXTRACT ALL USER-DEFINED ASSEMBLIES
-------------------------------------------------------------------------------
DECLARE @name nvarchar(max)
DECLARE @obj varbinary(max)

DECLARE #cur CURSOR FOR 
--SELECT af.name, af.content 
SELECT   REPLACE(
     REPLACE(af.name, '\', '_')
     , '/', '_')
  , af.content 
FROM sys.assemblies a
  INNER JOIN sys.assembly_files af 
   ON a.assembly_id = af.assembly_id 
WHERE is_user_defined <> 0

OPEN #cur

FETCH NEXT FROM #cur INTO @name, @obj


DECLARE @ObjectToken INT
DECLARE @path nvarchar(max)

WHILE @@FETCH_STATUS = 0
 BEGIN
  SET @path = @rootPath + @name
  PRINT @name + ' --> ' +  @path


  -------------------------------------------------------------------------------
  -- WRITE FILE TO DISK
  -------------------------------------------------------------------------------
  EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
  EXEC sp_OASetProperty @ObjectToken, 'Type', 1
  EXEC sp_OAMethod @ObjectToken, 'Open'
  EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @obj
  EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @path, 2
  EXEC sp_OAMethod @ObjectToken, 'Close'
  EXEC sp_OADestroy @ObjectToken


  FETCH NEXT FROM #cur INTO @name, @obj
 END


CLOSE #cur
DEALLOCATE #cur


PRINT ''
PRINT ''



-------------------------------------------------------------------------------
-- TURN Ole Automation Procedures OFF
-------------------------------------------------------------------------------
EXEC sp_configure 'show advanced options', 1;  
GO  
RECONFIGURE;  
GO  
EXEC sp_configure 'Ole Automation Procedures', 0;  
GO  
RECONFIGURE;  
GO  



Testato su SQL 2005. Via.

17 August 2018

How to disable the “Alt+Shift” shortcut to change language in Windows 10 (or Windows 8.1)

The option seems to have moved yet again for the latest Windows 10 update, at least for me (I no longer have a "Language" icon in the Control Panel).

Open the Region & Language settings applet.

Then "Advanced keyboard settings" in Related settings on the right.

Then "Language bar options".

The "Text Services and Input Languages" dialog will appear. Select the "Advanced Key Settings" tab and you'll be shown a Key Sequence list for changing between input languages.


Via.

29 June 2018

Add keys/values to Dictionary at declaration

Dim dict = New Dictionary(Of Integer, String) From
{
    {1, "Test1"},
    {2, "Test2"}
}



Via.

Visual Studio - SQL Schema Comparison Error “Source/Target is unavailable”

  1. Close all Visual Studio instances.
  2. Delete the saved connection keys in
    HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\ConnectionMruList
    
    (14.0 = Visual Studio 2017)
  3. Reopen VS and try again.



Via.

26 June 2018

25 May 2018

Access - Visibilità di una classe referenziata

Creo un file di Access ("Library.accdb") che viene referenziato da un altro file di Access ("FrontEnd.accdb").
Se creo una classe nella Library, non si vede nel FrontEnd.

  1. Dall'editor di VBA:
    • File / Esporta File (CTRL-E)
  2. Apri il file con un editor di testo
    • modificare gli attributi VB_Creatable e VB_Exposed da False a True:
      Attribute VB_Name = "MyClass1"
      Attribute VB_GlobalNameSpace = False
      Attribute VB_Creatable = True
      Attribute VB_PredeclaredId = False
      Attribute VB_Exposed = True
      
    • Salva il file
  3. In Access:
    • rimuovi la classe
    • crea una nuova classe vuota
    • seleziona tutto il codice e cancellalo
    • dal menu: Inserisci / File e scegliere il file modificato (ATTENZIONE: se si passa da "File / Importa" gli Attributi vengono resettati!!)
    • rimuovere questo codice VB:
    • VERSION 1.0 CLASS
      BEGIN
        MultiUse = -1  'True
      End
      

16 May 2018

Pass A User-Defined Table to a Stored Procedure

/* Create a table type. */
CREATE TYPE MyTableType AS TABLE 
( Column1 VARCHAR(50)
, ........ );
GO

/* Create a procedure to receive data for the table-valued parameter. */
CREATE PROCEDURE dbo. ValidateInputXML
    @TVP MyTableType READONLY
    AS 
     -- Do what ever you want to do with the table received from caller
    GO

/* Declare a variable that references the type. */
DECLARE @myTable AS MyTableType;

-- Fill @myTable with data and send it to SP. 
insert into @myTable SELECT * FROM @tmpInput TI WHERE TI.EntryType = 'Attribute';


/* Pass the table variable data to a stored procedure. */
EXEC ValidateInputXML @myTable ;
GO


https://stackoverflow.com/questions/30515297/pass-a-user-defined-table-to-a-stored-procedure

24 April 2018

Save text file UTF-8 encoded with VBA

Dim txt AS New ADODB.Command

With txt
 .Type = adTypeText
 .Charset = "utf-8"
 .Open
 
 .WriteText "special characters: äöüß"
 .WriteText "", adWriteLine    ' add an empty line, like WriteLine()
 .WriteText "another special characters: äöüß"
 
 .SaveToFile FileName, adSaveCreateOverWrite
 .Close
End With

Set txt = nothing


My version, from stackoverflow.com

17 April 2018

Virtual Box Bridged networking not working in Virtualbox under Windows 10

This fix this problem:

Enable "Windows 8" compatibility for VirtualBox executable: right-click on VirtualBox shortcut>Properties: in Properties dialog box: switch to "Compatibility" tab, under "Compatibility mode" section, select the check box next to: "Run this program in compatibility mode", make sure "Windows 8" is selected in combo box. click Ok, run VirtualBox again! (it's not needed to run as Administrator)


Via: https://stackoverflow.com/a/40204718

27 March 2018

SQL - Find last SQL Server restart (SQL Server uptime)

To find the SQL Server uptime:

SELECT   crdate AS startup 
  , + CAST((DATEDIFF(hh, crdate, GETDATE())) / 24 AS varchar(3)) + ' days and '
    + CAST((DATEDIFF(hh, crdate, GETDATE())) % 24 AS varchar(2)) + ' hours' AS days
FROM master..sysdatabases
WHERE name = 'tempdb'
Returns:
startup                 days
----------------------- ---------------------
2018-02-04 15:51:37.653 50 days and 20 hours


Works on Sql Server 2005 onward.

22 February 2018

String.Format function in VBA and VBScript

Public Function StringFormat(wFormat As String, ParamArray args()) As String
    
    Dim res As String
    Dim x As Long
    
    res = wFormat
    
    res = Replace(res, "\n", vbNewLine)
    res = Replace(res, "\t", vbTab)
    res = Replace(res, "\q", Chr(34))
    res = Replace(res, "\b", "•")    ' \b = Bullet
    
    For x = 0 To UBound(args)
        res = Replace(res, "{" & x & "}", Nz(args(x)))
    Next
    
    StringFormat = res
    
End Function

Usage example:
Debug.Print StringFormat("Hello {0}, it's {1}", "World", Now)
Returns:
Hello World, it's 22/02/2018 18:01:07




VBScript version, since VBScript doesn't allow ParamArray variables.
Note: "args" parameter could be a String or an Array()
Function StringFormat(wFormat, args)

    Dim res
    Dim x

    res = wFormat

    res = Replace(res, "\n", vbNewLine)
    res = Replace(res, "\t", vbTab)
    res = Replace(res, "\q", Chr(34))
    res = Replace(res, "\b", "•")    ' \b = Bullet

    if IsArray(args) Then
        For x = LBound(args, 1) To UBound(args, 1)
            res = Replace(res, "{" & x & "}", args(x))
        Next

    Else
        res = Replace(res, "{0}", args)

    End If

    StringFormat = res

End Function

Usage example:
wscript.echo StringFormat("Hello {0}", "World")
wscript.echo StringFormat("Hello {0}, it's {1}", Array("World", Now))

Returns:
Hello World
Hello World, it's 29/03/2018 11:58:54

14 February 2018

Notifica Job Falliti / sys_NotifyFailedJob_sp

CREATE PROCEDURE [dbo].[sys_NotifyFailedJob_sp]
(
   @recipients AS nvarchar(MAX)
 , @subjectPrefix AS nvarchar(100) = NULL
)
AS
BEGIN
 --##2018-02-14 - Boso -        sysjobsteps  // @body
 SET NOCOUNT ON

 DECLARE @JobID AS uniqueidentifier
 DECLARE @JobName AS nvarchar(255)
 DECLARE @subject AS nvarchar(255)
 DECLARE @body AS nvarchar(MAX) = ''
  

 DECLARE #JOBS CURSOR FOR
 SELECT job_id AS j
 FROM msdb..sysjobs j
 WHERE j.enabled <> 0


 OPEN #JOBS

 FETCH NEXT 
 FROM #JOBS 
 INTO @JOBID

 WHILE @@FETCH_STATUS = 0
  BEGIN
   DECLARE @PrevInstance AS int
   DECLARE @ErrCount AS int

   
   -- CERCA LA FINE DELLA History DELL'ULTIMA ESECUZIONE DEL JOB
   SELECT TOP 1 @PrevInstance = sjh.instance_id
   FROM msdb..sysjobhistory sjh WITH (NOLOCK)
   WHERE sjh.job_id = @JobID AND 
     sjh.step_id = 0    --> 0 = (Job outcome)
   ORDER BY
     sjh.instance_id DESC
     

   SELECT @PrevInstance = ISNULL(@PrevInstance, 0)


   -- CERCA PER I JOB ANDATI IN ERRORE
   SELECT @ErrCount = COUNT(*)
   FROM msdb..sysjobhistory sjh WITH (NOLOCK)
   WHERE sjh.job_id = @JobID AND 
     sjh.instance_id >= @PrevInstance AND 
     sjh.step_id = 0 AND   --> 0 = (Job outcome)
     sjh.run_status = 0
   


   -- CERCA SE UNO STEP DEL JOB E' ANDATO IN ERRORE
   SELECT @ErrCount = COUNT(*)
   FROM msdb..sysjobsteps s
   WHERE s.job_id = @JobID
    AND s.last_run_outcome = 0



   SELECT @ErrCount = ISNULL(@ErrCount, 0)


   -- MANDA LA MAIL
   IF @ErrCount > 0
    BEGIN
     SELECT   @jobName = j.name
       , @subject = LTRIM(ISNULL(@subjectPrefix, '') + ' Job "' + j.name + '" terminato CON ERRORI!')
     FROM msdb..sysjobs AS j WITH (NOLOCK)
     WHERE j.job_id = @JobID 



     -- COMPONE IL BODY DELLA MAIL
     SET @body = N'Job name:   ' + @JobName


     SELECT TOP 1 
       @body += N'
Step name:  ' + x.step_name + '

Message:
--------
' + x.message
     FROM msdb..sysjobhistory x
     WHERE x.run_status = 0
      AND x.job_id = @JobID
     ORDER BY 
       x.run_date DESC, x.run_time DESC



     SELECT TOP 1 
       @body += N'

Subsystem:  ' + s.subsystem + '
Command:    ' + s.command
   FROM msdb..sysjobsteps s
   WHERE s.job_id = @JobID
    AND s.last_run_outcome = 0
   ORDER BY 
     s.last_run_date DESC, s.last_run_time DESC



     EXEC msdb..sp_send_dbmail
        @recipients = @recipients
      , @subject =  @subject
      , @body_format =  'TEXT'
      , @body =  @body
    END
   
   
   FETCH NEXT 
   FROM #JOBS 
   INTO @JOBID
  END

 CLOSE #JOBS
 DEALLOCATE #JOBS

END
GO

12 January 2018

Clear RDP Connections History.bat

Occhio al nome documentI/documentS

@echo off
pause

reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers"

cd %userprofile%\documenti\
attrib Default.rdp -s -h
del Default.rdp

pause