// 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; using System.Data.OleDb; using System.Data.Odbc; namespace E { public class MainClass { private const int NINS = 20000; private const int SELREP = 50; private const string DATA = "This is a test with some dummy data"; public static void Test(string desc, IDbConnection con) { con.Open(); IDbCommand cre = con.CreateCommand(); cre.CommandText = "CREATE TABLE test(id INTEGER PRIMARY KEY, val VARCHAR(100))"; cre.ExecuteNonQuery(); DateTime dt1 = DateTime.Now; for(int i = 0; i < NINS; i++) { IDbCommand ins = con.CreateCommand(); ins.CommandText = "INSERT INTO test VALUES(" + i + ",'" + DATA + "')"; ins.ExecuteNonQuery(); } DateTime dt2 = DateTime.Now; Console.WriteLine(desc + ": INSERT " + NINS + " rows: " + (dt2-dt1).TotalSeconds + " seconds"); DateTime dt3 = DateTime.Now; for(int i = 0; i < SELREP; i++) { IDbCommand sel = con.CreateCommand(); sel.CommandText = "SELECT id,val FROM test"; IDataReader rdr = sel.ExecuteReader(); while(rdr.Read()) { int id = (int)rdr[0]; string val = (string)rdr[1]; if(val != DATA) { throw new Exception("Ooops"); } } rdr.Close(); } DateTime dt4 = DateTime.Now; Console.WriteLine(desc + ": " + SELREP + " SELECT " + NINS + " rows: " + (dt4-dt3).TotalSeconds + " seconds"); IDbCommand drp = con.CreateCommand(); drp.CommandText = "DROP TABLE test"; drp.ExecuteNonQuery(); con.Close(); } public static void Main(string[] args) { Test("SQL Client (2.0)", new SqlConnection(@"Server=ARNEPC3\SQLEXPRESS;Database=Test;Integrated Security=SSPI;")); Test("OLE DB (2000)", new OleDbConnection(@"Provider=SQLOLEDB;Data Source=ARNEPC3\SQLEXPRESS;Initial Catalog=Test;Integrated Security=SSPI;")); Test("ODBC (2000)", new OdbcConnection(@"Driver={SQL Server};Server=ARNEPC3\SQLEXPRESS;Database=Test;Trusted_Connection=yes;")); Test("OLE DB (2005)", new OleDbConnection(@"Provider=SQLNCLI;Data Source=ARNEPC3\SQLEXPRESS;Initial Catalog=Test;Integrated Security=SSPI;")); Test("ODBC (2005)", new OdbcConnection(@"Driver={SQL Native Client};Server=ARNEPC3\SQLEXPRESS;Database=Test;Trusted_Connection=yes;")); } } }