Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

SQL Statement Validator

Posted on June 28, 2013October 26, 2015 By David Kittell
using System.IO;
using Microsoft.Data.Schema.ScriptDom;
using Microsoft.Data.Schema.ScriptDom.Sql;

public List<string> SQLStmtValid(string sql)
	{
		TSql100Parser parser = new TSql100Parser(false);
		IScriptFragment fragment;
		IList<ParseError> errors;
		fragment = parser.Parse(new StringReader(sql), out errors);
		if (errors != null && errors.Count > 0)
		{
			List<string> errorList = new List<string>();
			foreach (var error in errors)
			{
				errorList.Add(error.Message);
			}
			return errorList;
		}
		return null;
	}

Reference: http://stackoverflow.com/questions/3276035/code-to-validate-sql-scripts

Originally Posted on June 28, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp MSSQL

Post navigation

Previous post
Next post

Related Posts

Red Hat – Failed to initialize NSS library

Posted on August 8, 2017

If you recently updated or recently installed a Red Hat server and get a message like this when trying to run yum the below will help. # yum repolist error: Failed to initialize NSS library There was a problem importing one of the Python modules required to run yum. The…

Read More

Update Windows Date/Time

Posted on December 8, 2013February 12, 2016

cls date 11-27-2013 time 5:19:00 PM w32tm /config /syncfromflags:manual /manualpeerlist:"time.windows.com" net stop w32time net start w32time w32tm /resync w32tm /resync pause GitHub: https://gist.github.com/dkittell/c3c930d1b432d51ebb71 Originally Posted on December 8, 2013Last Updated on February 12, 2016 All information on this site is shared with the intention to help. Before any source code…

Read More

Mac OSX Terminal – Clear Oh My ZSH History

Posted on April 9, 2018

If you have fallen in love with Oh My Zsh you likely have at one point realized it currently lacks the “history -c” option to clear your terminal history. This code below will help with that. #!/bin/sh # Clear_OhMyZsh_History.sh # # Script to remove all history or select content #…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes