Wednesday, February 26, 2020

Verbose truncation message

Do you get frustrated when you insert or update data and you get the message:

truncation occurred.

Microsoft finally heard us and is changing the message to give us more information.  If you are on SQL Server 2019 and have your compatibility level set to 150 then you already get the new error message.  If you aren't so lucky, but are using SQL Server 2017 CU12 or higher then you can enable traceflag 460 to get a detailed truncation message.

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql?view=sql-server-ver15

You can enable this traceflag by running

DBCC TRACEON(460)

This changes the truncation message for your current session to the form:

String or binary data would be truncated in table '<Table>', column '<column>'. Truncated value: '<value>'.

To disable you simply run

DBCC TRACEOFF(460)

You can verify it is off by running

DBCC TRACESTATUS

Wednesday, February 19, 2020

Viewing Windows Update Files

Windows no longer writes logs entries for Windows Update to "C:\Windows\WindowsUpdate.log".  If you open the file you will see the following:



So if you run get-windowsupdatelog powershell cmdlet, the system will generate log files in your current working directory.

If you run this on a Windows 2016 server you might get the following:

To fix, search the c:\windows\winSxS folder for SymSrv.dll and copy it to: c:\Program Files\Windows Defender\

Next time you run the cmdlet your files will be generated.

However, this generates a file that is basically useless.  To get usable information you need to download the symbol files, etc...

You can view the following technet article for more information:

https://social.technet.microsoft.com/Forums/en-US/4e81956f-9ed0-4dc2-be75-8fb54d065768/windowsupdatelog-no-format-information-found?forum=win10itprogeneral

Wednesday, February 5, 2020

Running applications as another user

There are many times that you want to run an application as a different user.  You might want to test out security as a different restricted user, or connect to a service on another domain.  This command should be able to help you out.  I wish I knew about it long ago, it would have saved me so much time.

Probably the simplest way to run an application as another user it to use the shift-right-click functionality in windows.  You do this by pressing the shift key and right-clicking on the application icon.  You then should get hte option to "Run as a different User".  You then are prompted for credentials.  Once authenticated the application will start running as that user.

This works great, but there are some issues.  The main issue that I always ran into was that the application is now running as the user you select.  You probably are thinking Duh!  But that means shortcuts to local resources like the Desktop or My Documents may not be accessible.  At the very least they will point to the resources for the account you are running as. 


So what other options are there?  There is a nifty command called runas.exe  There are a number of switches, but the ones I want to mention are /user and /netonly.  The /user switch defines which account you want to use.  You can enter it in the form of user@domain or domain\user. 

The second switch is /netonly. This help says this switch will only use the specified credentials for remote access only.  So when accessing services on the workstation you are logged into, or access local resources like your My Documents, you will be able to access them as you would with out the runas command.  However, if you try to connect to a remote resource on another machine the specified user account is now used.  This is amazing, I wish I would have known of this switch years ago!  This will be such a time saver as I use SQL Server Management Studio and frequently open and save scripts to local drives.

Now how do we use this?  The obvious way is to open a command prompt and type out the command in the following format:

runas.exe /netonly /user:Domain\user application

But that isn't always the best way.  A simpler way might be to create a shortcut.  This way you can simply just click the shortcut to start the application as the other user.  This is ideal if you perform this action a lot, saving you time by not having to type in the command.

To create the shortcut, just right right-click on your desktop and select new shortcut.  In the text box for the location enter the command above.  Next enter the name of the shortcut that you would like.  I like to use something in the form of 'SSMS as domain\user'.  Click finish and you are done.  Now if you want to be fancy then right-click on your new shortcut and select properties.  You can now modify any remaining properties like the Icon.  If you click "Change Icon..." and point to your application, it will probably have an embedded icon that you can use.  You can also right-click and pin to the start menu or taskbar, whichever you prefer.

Now that you have a shortcut you can run the application.  A command window will open prompting you for your password.  Enter it in and press Enter.


 If successful, you will see a message that it is attempting to start the application. 


Once the application starts you will be able to access the remote resources using the specified user.  Hope this helps someone out!