// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.SqlClient; namespace E { public class Program { public static void Test(string par) { using(SqlConnection con = new SqlConnection(@"Server=ARNEPC3\SQLEXPRESS;Integrated Security=SSPI;Database=Test")) { con.Open(); SqlCommand q = new SqlCommand("SP_TABLES " + par, con); SqlDataReader rdr = q.ExecuteReader(); while(rdr.Read()) { Console.WriteLine(rdr[0] + "." + rdr[1] + "." + rdr[2]); } } } public static void Main(string[] args) { // lidt setup using(SqlConnection con = new SqlConnection(@"Server=ARNEPC3\SQLEXPRESS;Integrated Security=SSPI;Database=Test")) { con.Open(); SqlCommand cre = new SqlCommand("CREATE TABLE supervigtig (id INTEGER IDENTITY PRIMARY KEY, txt VARCHAR(50))", con); cre.ExecuteNonQuery(); } // lidt sjov Console.WriteLine("As intended:"); Test("NULL, DBO"); Console.WriteLine("SQL injection:"); Test("NULL, DBO; DROP TABLE supervigtig"); Console.WriteLine("Verification:"); Test("NULL, DBO"); } } }