T-SQL Removing DB constraints

Quick post, aide-memoire, for disabling and then re-instating database contraints in MS-SQL.

EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"

EXEC sp_MSforeachtable @command1="PRINT '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL"
Advertisements

Windows PC not auto-booting?

Since I installed the “Windows 10 Fall Creators Update”, build 16299, the desktop has stopped auto-starting, to it’s BIOS configured schedule. It’s scheduled for a 5:01am start, but every morning I’ve come into the room, since the update, it’s sitting there switched off.

A couple of Google’s later and here’s the answer, well I hope it is as I haven’t verified it yet, something for tomorrow morning. So the suggestion is to disable Windows “fast startup” mode, details on doing that can be found over at TechAdvisor.co.uk, and a more detailed explaination of why is at HowToGeek.com.

29th October 2017: Seems to have resolved the issue.

Transact SQL – (Global) script variables

Problem:

When running a SQL script using the command sqlcmd tool if you switch context to another database, by using the “use database” command, then any variables defined before this are lost. A similar thing happens if you use the “go” command to group, or batch, commands in the script.

Solution 1:

Create a temporary table, e.g

CREATE TABLE #GlobalVariables (variableOne varchar(30), variableTwo int)
INSERT INTO #GlobalVariables (variableOne, variableTwo) VALUES ('ABCdef', 222222)

Solution 2:

Use script variables

:setvar variableOne "ABCdef"
:setvar variableTwo 222222

To access these in your SQL code you would do the following:

UPDATE #GlobalVariables SET variableOne = '$(variableOne)', variableTwo = $(variableTwo)

Setting update proxy in Notepad++

Having problems setting, and retaining, the Updater Proxy in the Notepad++ UI?

Then resort to the command line. Open a cmd prompt, with administrator privileges.
At the prompt go to the Notepad++ updater directory, the following works for default installations:

cd C:\Program Files (x86)\Notepad++\updater

From here run this command:

gup -options

This brings up the same dialog as the UI but this time the values you enter will be saved.

gup-options

 

The current identity (IIS APPPOOl\xxxxxxx) does not have write access to…

If you encounter the following error then this may be the fix you’re looking for.


Server Error in ‘/’ Application.


The current identity (IIS APPPOOL\xxxxx) does not have write access to ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files’.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The current identity (IIS APPPOOL\xxxxx) does not have write access to ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files’.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The current identity (IIS APPPOOL\xxxxx) does not have write access to ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files’.]
System.Web.HttpRuntime.SetUpCodegenDirectory(CompilationSection compilationSection) +10003412
System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +204

[HttpException (0x80004005): The current identity (IIS APPPOOL\xxxxx) does not have write access to ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files’.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9947380
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456

 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0


Simply run this code, from the Developer Command prompt: aspnet_regiis -i

Update 3-Jul-17:
On Windows Server 2012 you may need to run this command:

dism /online /enable-feature /featurename:IIS-ASPNET45 /all

 

Windows – using a local account with the free Windows 10 upgrade?

If so then, for the future, to enable you re-install Windows 10 you will need, before the free offer expires, to register your devices and their Digital Licences with your Microsoft Account.

If you already log into Windows 10 using your Microsoft Account then this has already happened and fresh installs will use that information when it comes to activating your Windows installation.
But if you haven’t then you need to do so ASAP, the free upgrade ends on the 29th July, 2016.

So if you use a local account to login then you need to go to Settings -> Update & security -> Activation and sign in with your Microsoft Account to associate that device and the Digital Licence

If you then want to auto login to Windows, without entering your password, then do the following:

  1. Press the Windows key & R, to bring up the run dialogue
  2. Enter netplwiz, and press enter
  3. Uncheck the “Users must enter a user name and password to use this computer” check box
  4. Click on “Apply”
  5. Enter your Windows account password, ignore the local user name displayed and do not enter the old password
  6. Reboot the PC, and all should be done

Repairing Windows

Just some random jottings on tools to repair Windows, release 10 and maybe 7 and 8 as well.

DISM (Deployment Image Servicing and Management)

Some of the options for this tool are not available depending on Windows version (Enterprise, Professional or Home) and also release.

Sample commands

  • DISM.exe /Online /cleanup-image /scanhealth
  • DISM.exe /Online /Cleanup-image /Restorehealth

SFC (System File Checker)

Tries to repair any file corruption in Windows files.

  • sfc /scannow
  • sfc /verifyonly

Embedding a file in an assembly

Why? I have some unit tests that need to run off of some pre-defined static XML data and while the tests run fine so long as the file and assembly are in the same location as soon as the assembly is moved elsewhere they start to fail, “file not found” exceptions.
So if the file is embedded in the assembly I don’t need to worry about where it is located anymore.

The assumption, in the following, is that the file is XML that has been serialised from an existing List and is being reloaded back into the same, and that the file is in the current assembly. “_states” is a global variable.

So here are the basic steps for this:

In your Solution Explorer view right-click on the file, in this case “state.xml”, and view it’s Properties, make sure that the “Build Action” is set to “Embedded Resource”, optionally set the “Copy to Output Directory” to “Do not copy”.

Once this has done then the file can be loaded and copied into the required object using:

GetFileFromAssembly

An important thing to remember is that the “Namespace” prefix to the file is the “Default namespace” as entered in the Application properties tab and not the namespace used in the referencing file.

You can reference the file, if it’s in a sub-folder by adding the folder just after the namespace, e.g.

GetFileFromAssemblyNamespace

 

 

VMWare memory configuration tweaks

Make sure the VM machine you’re going to be changing is shutdown/powered off first.
Then edit the .vmx file and add the following:


mainMem.useNamedFile = "FALSE"
MemTrimRate = "0"
sched.mem.pshare.enable = "FALSE"
prefvmx.useRecommendedLockedMemSize = "TRUE"
prefvmx.minVmMemPct = "100"

mainMem.useNamedFile – stop the VM from creating a memory mapped file (on disk).
MemTrimRate – Disable memory trimming.
sched.mem.pshare.enable – Disables memory sharing across running VM’s.
prefvmx.useRecommendedLockedMemSize – No idea, other than this WMWare KB article.
prefvmx.minVmMemPct – Preallocate all RAM available to the VM at startup, reducing this value allows some swapping to occur.

Update: 13-Jan-2016

It seems that this data can be configured on a global, for the current PC, basis. If the changes are applied to the c:\ProgramData\VMWare\VMWare Workstation\config.ini file.

And some additional settings can be added as well to further boost performance when the VM is in use.

priority.grabbed = "high"
priority.ungrabbed = "normal"


The grabbed setting can only be "high", or "normal".
The ungrabbed setting can have a value of "normal",
"low", or "idle".