Author’s Archive: ЈЦЅГЇП €ΘΘΚ

Home / ЈЦЅГЇП €ΘΘΚ
48 Posts

 

When we make manual backups we typically do so as insurance before applying updates, or to get a copy of a database for testing. We aren’t making backups to contribute to the backup regime, as that is the purvey of the automated backup jobs. The recommendation is to make out-of-band backups as described in the PDF document. An out-of-band backup can be deleted without causing problems and should be deleted when no longer needed.

We don’t (want to) know the particulars of our self-hosted customers’ backup regime, so it’s best that we not affect it, so out-of-band is the way to go.

Creating-an-out-of-band-SQL-database-backup.pdf

(This is a C# LinqPad script)

Using setvar in T-SQL

Finds the SQL Command Variable definitions in a SQL script and parses their names and values.
Finds the SQL Command Variable references and parses their names.
Determines which references have no definitions.
Determines which definitions have no references.

The definition names and reference names are case insensitive.
A definition is in the form of :setvar name “value”
A reference is in the form of $(name)

 

Note: The [Order] field is not unique in the database. The [Namespace] field is for multi-tenancy support.

Using setvar in T-SQL

 

It appears that the virtual machine manager in HyperV (VMM) reports the VM as running though the OS may not yet be fully loaded. We need to wait until the OS is responsive before continuing VM configuration. This observed behavior is more empirical than scientific and requires investigation, but a stop-gap solution is to wait until the VMM reports that the VM is running and then wait for the machine to respond to pings. This code does the second part.

 

SQL CMD tokens are replaced with their literal values prior TSQL parsing, so they can be used in places where a @ variable wouldn’t be permitted. Typically used for running queries within the SQL Server Management Studio, but such queries can be processed externally by calling SQLCMD.EXE (C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE). The literals are not scoped by GO statements like an @ variable and they can be re-defined later in the TSQL

Enable SQL CMD processing from the SQL Server Management Studio

EnableSQLCmdMode

Example SQL

Example C# – Using SQLCMD.EXE to run scripts

 

“Abstracted use case specific UML by implementing Java API used by the UI layer.”

The candidate could not explain what he meant by this statement and, since 2004, he has been periodically reminded of this. Yes, we hired him, yes it was the right choice. I am still receiving his paycheck garnishments.

“Please kindly do the needful”

The end of a cover letter from a person in India answering a posting for a local-only position. This became our team’s mantra for several years and is now a part of our regular language.

 

When a VM is created from a template machine that has SQL Server installed, that SQL instance must be told that the machine name has changed.

If a “foo” machine is created from a template named “template”, the T-SQL statement run against the default SQL instance select @@SERVERNAME returns “template” instead of the desired “foo”.

The solution is to execute the following T-SQL and then restart the SQL Server process.

Here’s a C# version of the rename and the SQL Server process restart using PowerShell and the SqlDataClient.

A configuration for SQL Server to prevent outgoing access to networked (off-machine) SQL Server instances from cloud VMs, while allowing management machines to access these instances.

SQL Server configuration for customer VMs

  • All SQL instances to be the default SQL instance on each machine (no named instances)
  • All SQL instances to use only TCP protocol (disable named pipes, and shared memory)
  • All SQL instances use port 1433 (already the case with template VMs)
  • All SQL instances do not run the SQL Browser Service (already the case with template VMs)
  • Management machines with SQL Server would not implement any special firewall rules aside from their current rule to allow incoming SQL requests.

Windows firewall configuration for VMs

Windows firewall properties for Domain, Private, and Public profiles
  • Inbound connections : block by default
  • Outbound connections allow by default
Create the following Windows firewall rules to block outgoing SQL requests:
  • Management machines with SQL Server would not implement these rules
  • DENY TCP remote port 1433,1434, any local port, any network profile, any program
  • DENY UDP remote port 1433,1434, any local port, any network profile, any program
Create the following Windows firewall rules to allow incoming SQL requests:
  • ALLOW TCP local port 1433 any remote port, any network profile, any program
  • ALLOW UDP local port 1433, any remote port, any network profile, any program
Use group policy to prevent users other than domain admins from changing firewall settings.

An alternate solution is to put a single firewall on the network between all machines and configure rules accordingly. This would make central management easier, but complicate the configuration.

 

Implementation #1

#1 Results

Implementation #2

#2 Results