title: Indexeddb IDBDatabase Exception 11 when db is newly created
body: <p>I have problem with indexeddb - I'm using this method to open and setup db</p>
  
  <pre><code>DBService.prototype.open = function (dbName, entity, cb) {
    var self = this;
    var req = indexedDB.open(dbName)
    req.onsuccess = function(e) {
      var v = 1;
      DBService.storage.db = e.target.result;
      var db = DBService.storage.db;
      // We can only create Object stores in a setVersion transaction;
      if (v != db.version) {
        var setVrequest = db.setVersion(v);
  
        setVrequest.onerror = function (err, stack) {
          console.log(err, stack);
        }
  
        setVrequest.onsuccess = function(e) {
          if(db.objectStoreNames.contains(entity)) {
            db.deleteObjectStore(entity);
          }
  
          var store = db.createObjectStore(entity,
            {keyPath: "timeStamp"});
          e.target.transaction.oncomplete = function() {
            console.log(db);
            cb(db);
          };
        };
      } else {
        cb(db);
        /*
        req.transaction.oncomplete = function() {
          cb(db);
        */
      }
    };
  
    req.onerror = function (err, stack) {
      console.log(err)
      console.log(stack)
    }
  };
  </code></pre>
  
  <p>Everything works nice except case when db is not ever opened. Im still getting </p>
  
  <pre><code>InvalidStateError: DOM IDBDatabase Exception 11
  </code></pre>
  
  <p>(when I console.log req.error)</p>
  
  <p>I know this code is pretty dirty now, I'm trying everything. I promise that when it will works well, then I will refactor it!</p>
  
  <p>Thank you!</p>