Ensuring a Remote Server is Available

Slides:



Advertisements
Similar presentations
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
Advertisements

Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
PHP (2) – Functions, Arrays, Databases, and sessions.
Asset: Academic Survey System & Evaluation Tool Bert G. Wachsmuth Seton Hall University.
Auditing Database DDL Changes with SQLVer. About PASS The PASS community encompasses everyone who uses the Microsoft SQL Server or Business Intelligence.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Copyright 2007– WinWare, Inc. Session: How to Utilize the Open Database Architecture of CribMaster Presenter: Phil Stenger.
MySql In Action Step by step method to create your own database.
Tom Castiglia Hershey Technologies
1 CHAPTER 3 CLASSES OF ATTACK. 2 Denial of Service (DoS) Takes place when availability to resource is intentionally blocked or degraded Takes place when.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Copyright © 2013 Curt Hill Database Security An Overview with some SQL.
QuikTrac 5.5, a validated Motorola Software Solution, allows you to take your Host ERP screens and extend them out to fixed or mobile devices including.
Oracle Data Integrator Procedures, Advanced Workflows.
Module 15 Monitoring SQL Server 2008 R2 with Alerts and Notifications.
Stored Procedure. Objective At the end of the session you will be able to know :  What are Stored Procedures?  Create a Stored Procedure  Execute a.
SQL Injection Jason Dunn. SQL Overview Structured Query Language For use with Databases Purpose is to retrieve information Main Statements Select Insert.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Get Rid of Cron Scripts Using Events Sheeri Cabral Senior DB Admin/Architect,
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
Ch 5. Introducing More Database Objects. Database Objects Table (ch2) View (ch3) Stored Procedure Trigger Function User-defined types.
Ch 7. Working with relational data. Transactions Group of statements executed as a group. If all statements execute successfully, changes are committed.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Dynamic SQL Writing Efficient Queries on the Fly ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
1. Advanced SQL Functions Procedural Constructs Triggers.
Improve query performance with the new SQL Server 2016 query store!! Michelle Gutzait Principal Consultant at
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
9 Copyright © 2005, Oracle. All rights reserved. Managing Undo Data.
SQL Database Management
Welcome POS Synchronize Concept 08 Sept 2015.
Now you don’t need to take any stress about the Cisco Exam
You Inherited a Database Now What?
Dynamic SQL Writing Efficient Queries on the Fly
Outsourcing Database Administration
Advanced Error Tracking Get to the root issue immediately!
DBA and IT Professional for ~9 years. Currently I am a Data Architect
SQL Saturday Pittsburgh
Cisco Data Virtualization
LCGAA nightlies infrastructure
Introduction to Networking
Dynamic SQL Writing Efficient Queries on the Fly
ROLAP partitioning in MS SQL Server 2016
Senior Software Engineering Student Robertas Sys
Net 431 D: ADVANCED COMPUTER NETWORKS
Cookies BIS1523 – Lecture 23.
DevOps Database Administration
Limiting SQL Server Exposure
DevOps Database Administration
5 WAYS TO BYPASS *OR ENSURE* SQL SERVER SECURITY MATT MARTIN
asset: Academic Survey System & Evaluation Tool
Fundamentals of Databases
Procedures Organized by Farrokh Alemi, Ph.D. Narrated by Yara Alemi
Limiting SQL Server Exposure
DBA for ~4+years, IT Professional for 7.5 years.
REAL-TIME, INTERACTIVE DOCUMENT AUTOMATION
Outsourcing Database Administration
Chapter 7 Using SQL in Applications
You Inherited a Database Now What?
Chapter 7 Using SQL in Applications
PRACTICE OVERVIEW PL/SQL Part - 1.
Copyright © 2013 – 2018 by Curt Hill
Data Definition Language
From ACCEPT to MASQUERADE Tim(othy) Clark (eclipse)
Sql Saturday Philadelphia
How to build a T-SQL Framework SQL Performance for Developers
Presentation transcript:

Ensuring a Remote Server is Available Checking the Circuit Ensuring a Remote Server is Available Ed Wagner

About Your Presenter Senior DBA at RDA Group, Global Market Research and Consulting 23 years experience working with databases Frequent poster on SQLServerCentral.com Specialize in high-performance T-SQL I actually enjoy this stuff.  Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

Background A Special Email System We’re required to send automatically- generated email to our customers in China on both a manual and scheduled basis. China likes to keep everything inside China and is hostile to receiving email from outside China. To get around that, we set up an SMTP server in Hong Kong with a VPN tunnel. That’s where the trouble starts. Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Problem The “Tunnel” Occasionally Collapsed The tunnel was found to collapse from time to time. We had to know if the tunnel was up to be able to send email through it. Having “lost” or “not sent” emails is not an option. To support automatic “email sent” tracking, any fix had to be a part of the existing email system, which consists of stored procedures that call SQL Server’s database mail engine. Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

Restrictions on Solutions They want it REAL BAD! Must be inexpensive to develop. Must be inexpensive to implement. No additional 3rd party solutions. Needed NOW! Must be easily used by existing stored procedures. Because of that, cannot be an OS-only solution. Did I mention they need it NOW and it has to be inexpensive? Just because they want it “real bad”, we don’t need give it to them that way.  Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Solution Keep it Simple and Inexpensive ICMP traffic was permitted by both firewalls, so a DOS “ping” would work. Write a procedure to use a ping to see if the remote server is up. If not, continue trying until it responds or the predefined time period elapses. The return value tells the calling procedure if the server is up. Since the developers who will be calling the procedure cannot use xp_cmdshell, define the procedure to execute as owner and grant execute permission on the procedure to the developer. Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Code - Initialization CREATE PROCEDURE dbo.VerifyChinaMailServer WITH EXECUTE AS OWNER AS BEGIN ------------------------------------------------------------------------------------- --Initialization SET NOCOUNT ON; --Local variables DECLARE @dtmEnd Datetime, @strCmd Varchar(200); --Setup to try to ping the remote server for up to 5 minutes SELECT @dtmEnd = DATEADD(minute, 5, GETDATE()), --Only try for 5 minutes @strCmd = 'ping ChinaMailServer1 -n 1 -w 1000 | findstr Reply'; --Create a temp table to capture the results of our DOS command IF OBJECT_ID('tempdb.dbo.#ping', 'u') IS NOT NULL DROP TABLE #ping; CREATE TABLE #ping ( Response Varchar(200), ID Integer not null identity (1, 1)); Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Code – Ping the Server --------------------------------------------------------------------------------------- --Ping the destination server. If not there, ping again until it’s time to give up WHILE GETDATE() < @dtmEnd --While we're still within the time limit... BEGIN --Make sure the command shell is still enabled IF (SELECT CONVERT(Integer, value_in_use) FROM sys.configurations WHERE name = 'xp_cmdshell') = 0 EXECUTE sp_configure 'xp_cmdshell', 1; RECONFIGURE; END; --Ping the remote server and trap the results INSERT INTO #ping(Response) EXECUTE master.dbo.xp_cmdshell @strCmd; --If any non-null row is returned in the response, a reply was received --so we can break out of the loop immediately IF (SELECT MAX(ID) FROM #ping WHERE Response IS NOT NULL) IS NOT NULL BREAK; --A 1-second max time is built in to our ping command, so no need to pause Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Code – Is Server There? ----------------------------------------------------------------------------- --Return the status of the remote server IF (SELECT MAX(ID) FROM #ping WHERE Response IS NOT NULL) IS NOT NULL RETURN 1; --Ping successful. Server IS available ELSE RETURN 0; --Ping NOT successful. Server is NOT available --Housekeeping DROP TABLE #ping; END; Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

The Code – Example Usage --Declare an obviously named variable DECLARE @intOK Integer; --Get the availability status of the remote server EXECUTE @intOK = dbo.VerifyChinaMailServer; SELECT @intOK; Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved

Conclusion Takeaways: This is an example of being given a problem by systems, using what we already know to use to solve the problem, and make it available to others to use WITHOUT elevating THEIR privs. Takeaways: Even with all the tools available today, DOS is still our friend. It keeps us from reinventing the wheel and prevents the “Tower of Babel”. When used properly, xp_cmdshell is very useful. When configured properly, it is also safe. (larger discussion) There actually ARE times when a loop is appropriate. Ensuring a Remote Server is Available 07 September 2015 © Copyright by Ed Wagner - All Rights Reserved