Category Archives: Notes to Myself

Things I’ve figured out and want to remember how to do the next time around.

Creating a Database Upon Deploy of Microsoft Web Site

Our development work includes a website we are creating for a client for whose system we don’t have direct access. We need a way to create a Web Deploy Package that we can turn over to them and ask them to deploy on their system.

Creating the Web Deploy Package was easy – just follow the directions that can be found in a number of places to use the GUI within Visual Studio 2012 and create it. The hard part was getting the database to create itself.

Theoretically, according to what I was reading, I should have to do is click the box that says, Execute Code First Migrations (runs on application start). Nope. Didn’t work. The database wasn’t created when I deployed. And, when I ran the application, nothing happened; no database was created.

I did try creating the database before running the app, then expecting the tables to be created. but they weren’t.

After much struggling, and a whole lot of research, I finally got it working. The following are the steps that I needed to have in place for this to occur:

  1. Within your Configuration.cs (if using C#) file (created automatically when you create a migration), set:
    • AutomaticMigrationsEnabled = true
  2. Create a duplicate of your connection string in your web.config file.
    • In the deployment settings, on the first string (your original string), check the box that says Execute Code First Migrations (runs on application start)
    • On the second string, check the box that says, Update database
  3. Create a database user for your database. Windows Authentication didn’t work. Neither did ‘sa’, although that was supposed.
  4. Upload some data. Click the Configure database updates link on the Settings. You’ll be given the option to add SQL files to run after the database is created. Attach one with some minimal data for your database.

And that worked! I created the database on the other server. I created the user, with SA access on the new database. I ran my deployment script, as per the instructions provided and voila! the new tables were created and populated!

 

Cyrus Upgrade Error on Ubuntu

For several months now, I’ve been getting an error every time I tried to do an upgrade of my ubuntu system:


 Converting from /var/lib/cyrus/deliver.db (berkeley-nosync) to /tmp/deliver.db.cOT3kOvz (skiplist)
 fatal error: can't open old database
 dpkg: error processing cyrus-common-2.4 (--configure):
 subprocess installed post-installation script returned error exit status 75
 dpkg: dependency problems prevent configuration of cyrus-pop3d-2.4:
 cyrus-pop3d-2.4 depends on cyrus-common-2.4 (= 2.4.12-2); however:
 Package cyrus-common-2.4 is not configured yet.
 dpkg: error processing cyrus-pop3d-2.4 (--configure):
 dependency problems - leaving unconfigured
 dpkg: dependency problems prevent configuration of cyrus-pop3d:
 cyrus-pop3d depends on cyrus-pop3d-2.4; however:
 Package cyrus-pop3d-2.4 is not configured yet.
 dpkg: error processing cyrus-pop3d (--configure):
 dependency problems - leaving unconfigured
 

I tried removing cyrus altogether. But there were so many inter-dependencies that it wasn’t an option.

I finally found a clue as to how to fix it here, but I had to modify it a bit for my own situation.

I moved the deliver.db and tls_sessions.db files, then ran the upgrade command and voila! everything worked!


 sudo su -
 cd /var/lib/cyrus
 mv deliver.db deliver.db.old
 mv tls_sessions.db tls_sessions.db.old
 

Once the upgrades are done, the ‘old’ files can be removed. Yes, you might be able to get away with just deleting those files in the first place. But I like to play it safe.

Note: does this mean that there may be local mail not delivered? It could. But my local mail is only used for notifications, so it wasn’t a big deal to me.

LINQ and Dynamic Queries

Our users need to filter through a list of groups from one list to bring in the groups that should have access on another. The one list is overwhelming, since a group may be created on the fly for special purposes at any time. But the list of groups needed for this secondary application may be quite small in comparison.

But each users’ organization will have a different beginning and ending group list. So filtering criteria will be different for each. Hence, to provide that capability, I need to be able to create filters for these lists dynamically.

Looking for a solution, I ran across this article that I thought would work. But it broke down when I tried to use more than one ‘where’ statement.

The solution I did use may not be elegant. And I’m hoping it can be made more so, yet more flexible, in the future. But it works. So I wanted to pass it on, in case someone else could use it:

public static List GetFilteredRoles(List roleFilterList) {
   EntityObject context = new EntityObject();
   IQueryable matches = context.Roles;
   List integers = new List();

   IEnumerable filterSet = from r in context.Roles
                                 select r;
            

// now figure out a filter

   foreach (GroupFilterCLR filter in roleFilterList) {
      String strTmp = filter.Regex;
      List tmp = new List();
      if (filter.Status == FilterStatus.INCLUDE) {
         if (filter.Relation == FilterRelation.CONTAINS) {
            tmp = (from r in context.Roles
                   where r.Name.Contains(strTmp)
                   select r).ToList();
                       
          } else if (filter.Relation == FilterRelation.STARTS_WITH) {
               tmp = (from r in context.Roles
                     where r.Name.StartsWith(strTmp)
                     select r).ToList();

          } else if (filter.Relation == FilterRelation.ENDS_WITH) {
                tmp = (from r in context.Roles
                       where r.Name.EndsWith(strTmp)
                       select r).ToList();
          }
                    
      } else {
         if (filter.Relation == FilterRelation.CONTAINS) {
            tmp = (from r in context.Roles
                   where !r.Name.Contains(strTmp)
                   select r).ToList();
          } else if (filter.Relation == FilterRelation.STARTS_WITH) {
                     tmp = (from r in context.Roles
                            where !r.Name.StartsWith(strTmp)
                            select r).ToList();
          } else if (filter.Relation == FilterRelation.ENDS_WITH) {
                      tmp = (from r in context.Roles
                             where !r.Name.EndsWith(strTmp)
                             select r).ToList();
           }
        }
           filterSet = filterSet.Intersect(tmp);
      }
   return Mapper.Map<List<Role>, List<RoleDTO>>(filterSet.ToList());

}

Notice, too, that it shows how to negate an expression.