Exemple #1
0
        public void Import(DataFile file)
        {
            string database = file.database;

            if (!context.DatabaseExists(database))
            {
                context.CreateDatabase(database);
                context.ChangeDatabase(database);
            }

            DataTable csvData = CSVReadWrite.ReadCsvDataTable(file.path);

            context.ExecuteBulkCopy((bulkCopy) => CreateDatabaseTable(file, csvData, bulkCopy));
        }
Exemple #2
0
        public void Import(DataFile file)
        {
            if (context.DatabaseExists(file.database))
            {
                throw new InvalidOperationException("database already exists");
            }

            Restore          restore = new Restore();
            BackupDeviceItem backup  = new BackupDeviceItem(file.path, DeviceType.File);

            restore.Database = file.database;
            restore.Devices.Add(backup);

            RelocateFile relocateDataFile = new RelocateFile(LookupLogicalName(restore, "D"), string.Format(savePath, file.database, DataConfig.mdfExt));
            RelocateFile relocateLogFile  = new RelocateFile(LookupLogicalName(restore, "L"), string.Format(savePath, file.database, DataConfig.ldfExt));

            restore.RelocateFiles.Add(relocateDataFile);
            restore.RelocateFiles.Add(relocateLogFile);
            restore.Action          = RestoreActionType.Database;
            restore.ReplaceDatabase = false;
            restore.SqlRestore(SQLServerContext.Server);

            context.ChangeDatabase(file.database);
        }