13 June 2017

SQL - Restore database backup over the network

How do you restore a database backup using SQL Server over the network? You have few options to use a network file as a backup source

1) Map network drive/path, hosting file, under SAME user as MS-SQL Server.

2) Use xp_cmdshell extended stored procedure to map network drive from inside of MS SQL
-- allow changes to advanced options 
EXEC sp_configure 'show advanced options', 1
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO
-- To enable xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO
EXEC xp_cmdshell 'NET USE Z: "\\Srv\Path password1 /USER:Domain\UserName /PERSISTENT:NO "'


--> Afterwards drive Z: will be visible in Server Managment studio, or just

RESTORE DATABASE DataBaseNameHere FROM DISK = 'Z:\BackNameHere.BAK'



-- DISABLE FLAGS

-- To enable xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 0
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO

-- allow changes to advanced options 
EXEC sp_configure 'show advanced options', 0
GO
-- Update currently configured values for advanced options.
RECONFIGURE
GO


via.

12 June 2017

SQL - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

Se si incontra questo errore:
Msg 242, Level 16, State 3, Procedure MyProcedure_sp, Line 35
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

Succede quando la lingua del sistema operativo o di SQL Server è diversa da quella utilizzata nell'applicazione; bisogna modificare la lingua dell'utente:

- Security
- Logins
- Proprietà dell'utente:
- Cambiare la lingua: Italiano o British English (stesso formata data/ora, ma messaggi in inglese)


Oppure usare SET DATEFORMAT DMY prima di ogni EXEC...