title: System Data Entity. The underlying provider failed on Open
body: <p>I am creating 2 projects that have the same database (it's an MDF database).  The first one is the map editor, and I use XNA 4 and Web Services to connect to it.  The second one is the game itself and uses XNA 3.1 and Entity Data Model to connect database. </p>
  
  <p>When I run the map editor and access the database, it runs properly. Bbut when I run the game and access the database, it shows an error "The underlying provider failed on Open"</p>
  
  <p>I think the connection from the web service is not closed yet.  But I don't know where I should close the connection.</p>
  
  <p>Here is my code from the web service:</p>
  
  <pre><code>public Map AddNewMap(string username, string mapName, int sizeX, int sizeY)
      {
          using (BaseModelDataContext context = new BaseModelDataContext())
          {
              Map newMap = new Map()
              {
                  Username = username,
                  Name = mapName,
                  SizeX = sizeX,
                  SizeY = sizeY,
                  Upload_Date = DateTime.Now,
                  Status = 0
              };
  
              context.Maps.InsertOnSubmit(newMap);
              context.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
              context.Dispose();
              return newMap;
          }
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Here is the entity data model code :</p>
  
  <pre><code>using (MazeEntities ent = new MazeEntities())
          {
              ent.Connection.Open();
              return (from map in ent.Map
                      select map).ToList&lt;Map&gt;();
          }
  </code></pre>
  
  <p>This code runs properly if I did not use the web service before.  If I use the web service first, it shows an error at ent.Connection.Open();</p>
  
  <p>Here is the inner exception:</p>
  
  <blockquote>
    <p>Cannot open user default database. Login failed.\r\nLogin failed for user 'erkape-PC\erkape'.</p>
  </blockquote>
  
  <p>Connection string for web service :</p>
  
  <blockquote>
    <p>connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\3DMapDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"</p>
  </blockquote>
  
  <p>Connection string for the game:</p>
  
  <blockquote>
    <p>"metadata=res://<em>/MazeDataModel.csdl|res://</em>/MazeDataModel.ssdl|res://*/MazeDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=D:\eRKaPe\DropBox\TA\Program\3D_Map_Editor\3DMapEditorServices\App_Data\3DMapDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /></p>
  </blockquote>