/// <summary> /// Set up the SQL connections for the table adapters when creating/opening /// a database. /// </summary> private void CreateConnections() { localDB = new DPDatabaseImportV1(); localTAManager = new DPDatabaseImportV1TableAdapters.TableAdapterManager(); localTAManager.ChatLogTableAdapter = new DPDatabaseImportV1TableAdapters.ChatLogTableAdapter(); // DVS/DirectParse uses SQLCE 3.1, so we can always do an upgrade here. System.Data.SqlServerCe.SqlCeEngine sqlCeEngine = new System.Data.SqlServerCe.SqlCeEngine(databaseConnectionString); // Creates a 0-byte file. We need the name, but don't want the file to exist. tempDatabaseName = Path.GetTempFileName(); File.Delete(tempDatabaseName); string tempConnectionString = string.Format("Data Source={0}", tempDatabaseName); sqlCeEngine.Upgrade(tempConnectionString); Properties.Settings.Default.Properties["DvsParse_SaveConnectionString"].DefaultValue = tempConnectionString; System.Data.SqlServerCe.SqlCeConnection sqlConn = new System.Data.SqlServerCe.SqlCeConnection(tempConnectionString); localTAManager.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Connection = sqlConn; localTAManager.ChatLogTableAdapter.Fill(localDB.ChatLog); }
public void CloseDatabase() { if (localTAManager != null) { localTAManager.Dispose(); localTAManager = null; } if (localDB != null) { localDB.Dispose(); localDB = null; } if (tempDatabaseName != string.Empty) { if (File.Exists(tempDatabaseName)) { File.Delete(tempDatabaseName); } } }