Wednesday, June 13, 2018

'TRUNCATE_ONLY' is not a recognized BACKUP option.

In Microsoft SQL server 2000 and 2005, as part of the ‘BACKUP LOG’ command, there was an option to truncate the log file, without storing a backup to file. In Microsoft SQL Server 2008, this option has been removed, and you can now no longer use the ‘TRUNCATE_ONLY’ option when performing a transaction log backup.

The truncate only option is used to truncate the log file. This is generally done so you can then shrink the transaction log file, and recover the disk space back to the file system.

I ran into this issue, when we are migrating our servers from 2005 to higher version.

Msg 155, Level 15, State 1, Line 1
'TRUNCATE_ONLY' is not a recognized BACKUP option.

To truncate the transaction log file in Microsoft SQL Server 2008 or 2012 and above, without making an actual transaction log backup (possibly due to free space limitations), you need to change the recovery model of the database to “Simple”, and then change it back to “Full” (or “Bulked Logged” if that’s what it was previously).

USE ps;
GO

-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE ps
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (ps_log, 1);  
-- here 2 is the file ID for trasaction log file
--you can also mention the log file name (dbname_log)
GO

-- Reset the database recovery model.
ALTER DATABASE ps
SET RECOVERY FULL;
GO

Hope this helps.

Sunday, June 10, 2018

Quick note: How to find queries, SP's or jobs that use a linked server?

Here is the query below that can pull all above results.

Declare @VName varchar(256)
Declare Findlinked cursor
LOCAL STATIC FORWARD_ONLY READ_ONLY
     FOR
Select name
   From sys.servers
   Where is_linked = 1
      
Open Findlinked;
Fetch next from Findlinked into @VName;

while @@FETCH_STATUS = 0
Begin
   SELECT OBJECT_NAME(object_id) 
      FROM sys.sql_modules 
      WHERE Definition LIKE '%'+@VName +'%' 
      AND OBJECTPROPERTY(object_id, 'IsProcedure') = 1 ;
      
   Fetch next from Findlinked into @VName;
End

Close Findlinked
Deallocate Findlinked

SSIS Jobs are different, Here is one for SSIS jobs with Job Name and Details

Declare @VName varchar(256)
Declare Findlinked cursor
LOCAL STATIC FORWARD_ONLY READ_ONLY
     FOR
Select name AS name
   From sys.servers
   Where is_linked = 1
      
Open Findlinked;
Fetch next from Findlinked into @VName;

while @@FETCH_STATUS = 0
Begin
   SELECT OBJECT_NAME(object_id) as ProcedureName 
      FROM sys.sql_modules 
      WHERE Definition LIKE '%'+@VName +'%' 
      AND OBJECTPROPERTY(object_id, 'IsProcedure') = 1 ;
      
   Fetch next from Findlinked into @VName;
END
Close Findlinked

Open Findlinked;
Fetch next from Findlinked into @VName;

while @@FETCH_STATUS = 0
Begin
   SELECT j.name AS JobName,js.command 
      FROM msdb.dbo.sysjobsteps js
         INNER JOIN msdb.dbo.sysjobs j
            ON j.job_id = js.job_id
      WHERE js.command LIKE '%'+@VName +'%'
   Fetch next from Findlinked into @VName;
END

Close Findlinked
Deallocate Findlinked

Friday, June 08, 2018

Fun with Keyboard Shortcut Keys

  1. Ctrl+Alt+Down Arrow. This key command can magically rotate your monitor screens to 180 degrees. It would be very interesting to see someone try to log in to their PC and be surprised by an upside down screen. It would be pretty funny to see someone get dumbfounded by this shortcut. But do keep in mind is that this key only works with computers who have Intel graphics chipsets and may not work on all PCs.
  2. Left Alt + Left Shift + Print Screen. This amusing shortcut is a great way to both irritate and puzzle your friends; this command turns on the high contrast visibility setting on any computer set.
  3. Ctrl + F4. You can use this shortcut to sneak-up and wreck havoc on your pals who are working on just about any MS Office program. This shortcut immediately exits the document that is currently running and will most probably upset the victim. So be ready to run away just in case he or she gets violent.
  4. Windows + M. This command is a bit more advanced than the one above, because aside from shutting your current program, it also closes all your opened programs in a blink of an eye. Again, be ready to run or to defend yourself when executing this prank.
  5. Windows + D then Alt + F4 then press enter. This command is at the top rung when it comes to instantly closing programs. What does it do? Well, it just closes any version of windows as soon as you enter the shortcut, which makes it a very effective pal irritant.
  6. Ctrl + H. If you are at your friend’s place and have access to his or her computer, you can use this keyboard shortcut to get easy access to his or her browsing history. Be warned though, that this can reveal way too much information about your friend, so be ready for anything before trying this out.
  7. Left Alt + Left Shift then enter. This command will make your Num Lock key beep every time it is pressed. It doesn’t do any harm but it can make your friend’s computer seem broken by giving off an odd beep.
  8. Windows key + “+” then Ctrl + Alt + F. This shortcut makes your screen bigger, which can annoy users who prefer a certain screen size.
  9. PRT SC, Ctrl+V to make an unclick-able desktop. Press “Print Screen” on your keyboard (PRT SC) to make a screenshot of your desktop. Now go to Paint and Paste using (Ctrl+V). You will now have an image of your desktop which you must then save to your PC (not on your desktop) and save it as BMP. You’ll now have the file like this: C:/Desktop.bmp. Next, right-click on your desktop and select Properties. Select the tab Desktop and click Browse… Navigate to your screenshot and press OK to set it as your background. Right-click your desktop again and navigate to “Arrange icons by” and uncheck “Show desktop icons”. Your icons are now effectively unclickable, and the next user will probably give up in frustration.
  10. Windows key + “+” then windows key + “-” then Ctrl + Alt + I. This shortcut can turn the colors on your monitor screen upside down; it’s another great prank to make it seem that the computer is busted.

Quicknote: install stunnel as service

stunnel is an open-source multi-platform application used to provide universal TLS/SSL tunneling service. stunnel is used to provide secure encrypted connections for clients or servers that do not speak TLS or SSL natively.

Installing and setting up is pretty standard and configuration is derived form stunnel.config file, Here is how you can setup and configure stunnel in windows

For setting up stunnel service as automatic run this command from command prompt: “stunnel.exe -install  -quiet" and start it.

This will install stunnel as service, open the service and set service as automatic and start service.

stunnel

How to Configure Stunnel Windows

stunnel is an open-source multi-platform application used to provide universal TLS/SSL tunneling service. stunnel is used to provide secure encrypted connections for clients or servers that do not speak TLS or SSL natively.

stunnel can be used as TLS proxy, I have used when we have issues with TLS 1.0 with one of API End point.

Server administrators and home users alike feel the pressure to secure their Internet communications, but not every application supports using Transport Layer Security (TLS). Recently all OS and all major stopped TLS 1.0 support. So we used Stunel as an fall back approach to TLS 1.0.

Step 1
Install Stunnel. Download the Windows binary file from Stunnel.org. Double-click on the executable "stunnel-4.34-installer.exe" and accept the default values for installing Stunnel on your computer.

Step 2
Copy a valid SSL public certificate to the directory "C:\Program Files (x86)\stunnel." To make things more trouble-free, combine the public key and private key certificates into one .PEM file.

Step 3
Modify the Stunnel configuration file. Open the file "C:\Program Files (x86)\stunnel\stunnel.conf" using a text editor such as Notepad. Modify the file to include the line "cert = C:\Program Files (x86)\stunnel\," where is the name of your certificate file.

Here is the example of my config file

client = yes
[myService1]
accept          = 4010
connect         = www.pld.ups.com:443
sslVersion 	= TLSv1.2

[myService2]
accept          = 4011
connect         = wwwcie.ups.com:443
sslVersion 	= TLSv1.2

Step 4
Configure Stunnel to start automatically. Navigate to the Start menu, "stunnel" folder and click on "Service Install." Stunnel will configure a Windows service called "stunnel" to start automatically when the computer boots.