public void LinqToSqlDataContext02() { Console.WriteLine("*********** Verify Northwind DB exists ***********"); if (db.DatabaseExists()) Console.WriteLine("Northwind DB exists"); else Console.WriteLine("Error: Northwind DB does not exist"); Console.WriteLine(); Console.WriteLine("********* Verify NewCreateDB does not exist **********"); string userTempFolder = Environment.GetEnvironmentVariable("Temp"); string userMDF = System.IO.Path.Combine(userTempFolder, @"NewCreateDB.mdf"); NewCreateDB newDB = new NewCreateDB(userMDF); if (newDB.DatabaseExists()) Console.WriteLine("Error: NewCreateDB DB exists"); else Console.WriteLine("NewCreateDB DB does not exist"); }
public void LinqToSqlDataContext01() { // Create a temp folder to store the new created Database string userTempFolder = Environment.GetEnvironmentVariable("SystemDrive") + @"\LinqToSqlSamplesTemp"; Directory.CreateDirectory(userTempFolder); Console.WriteLine("********** Create NewCreateDB ***********"); string userMDF = System.IO.Path.Combine(userTempFolder, @"NewCreateDB.mdf"); string connStr = String.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;Connect Timeout=30;User Instance=True; Integrated Security = SSPI;", userMDF); NewCreateDB newDB = new NewCreateDB(connStr); newDB.CreateDatabase(); if (newDB.DatabaseExists() && File.Exists(Path.Combine(userTempFolder, @"NewCreateDB.mdf"))) Console.WriteLine("NewCreateDB is created"); else Console.WriteLine("Error: NewCreateDB is not successfully created"); Console.WriteLine(); Console.WriteLine("********* Insert data and query *********"); var newRow = new Person { PersonID = 1, PersonName = "Peter", Age = 28 }; newDB.Persons.InsertOnSubmit(newRow); newDB.SubmitChanges(); var q = from x in newDB.Persons select x; ObjectDumper.Write(q); Console.WriteLine(); Console.WriteLine("************ Delete NewCreateDB **************"); newDB.DeleteDatabase(); if (File.Exists(Path.Combine(userTempFolder, @"NewCreateDB.mdf"))) Console.WriteLine("Error: NewCreateDB is not yet deleted"); else Console.WriteLine("NewCreateDB is deleted"); // Delete the temp folder created for this testcase Directory.Delete(userTempFolder); }