All data and metadata inside a LoBDb.NET database can be backuped and restored. The format of a backup file is the same for all supported DBMS. One thing to notice is that when restoring the user list, the password of each restored user is set to a default value (RestoreTask.DefaultUserPassword).

            var domainConfig = new DomainConfiguration
            {
                DbProviderName = "MSSQLSERVER",
                DbConnectionString = new SqlServerConnectionStringBuilder
                {
                    DbName = "TestDb",
                    Host = @".\SQLEXPRESS",
                    UserName = "Admin",
                    UserPassword = "P@assw0rd",
                    Driver = "SQL Server"
                }.Build()
            };
            var domain = Domain.Build(domainConfig);
            domain.DeleteAll();

            // Groups
            var groupTable = domain.AddTable("groups");
            groupTable.GrantAll();

            // Group name
            var groupName = (StringColumn)groupTable.AddColumn("name", ColumnType.String);
            groupName.IsNotNull = true;

            // Students
            var studentTable = domain.AddTable("students");
            studentTable.GrantAll();

            // Student name
            var studentName = (StringColumn)studentTable.AddColumn("name", ColumnType.String);
            studentName.IsNotNull = true;
            studentName.MaxLength = 80;

            // Group id
            var groupId = (RefColumn)studentTable.AddColumn("group_id", ColumnType.Reference);
            groupId.IsNotNull = true;
            groupId.AddTarget(groupTable).HasCascadeDelete = true;

            // Adding a group
            var group1Id = groupTable.InsertRow(groupName.Value("My group"));

            // Adding two students
            var student1Id = studentTable.InsertRow(studentName.Value("Student 1"),
                groupId.Value(group1Id));
            var student2Id = studentTable.InsertRow(studentName.Value("Student 2"),
                groupId.Value(group1Id));

            // Creating a backup
            new BackupTask(domain).Run();

            // Deleting everything
            domain.DeleteAll();

            Console.WriteLine("Table count = {0}", domain.Tables.Count);

            // Restoring
            new RestoreTask(domain).Run();

            // Reading students
            var name = studentName.EmptyValue();
            var gId = groupId.EmptyValue();

            studentTable.ReadAllRows(() =>
                {
                    Console.WriteLine("Student: name = {0}, group id = {1}",
                        name.GetString(),
                        gId.GetGuid());
                }, name, gId);

Last edited Jul 21, 2012 at 10:13 PM by mapase, version 1

Comments

No comments yet.