0

I created database with ef code first. I copied the 2 files that ef created to the project folder DAL.UsersDb.mdf and DAL.UsersDb_log.ldf

Now I want to tell the project to use the new location. I added them to config file but its not working

<add name="UsersDb"
   connectionString="Data Source=(LocalDB)\v11.0;
   initial catalog=UsersDb;
             AttachDBFilename=|C:\Users\HOME\Desktop\MyProject|\DAL.Funcs+DataBase.mdf";
             integrated security=True;  MultipleActiveResultSets=True;  App=EntityFramework"
   providerName="System.Data.SqlClient" />

I got the following Exception:

Cannot open database \"DAL.UsersDb\" requested by the login. The login failed.\r\nLogin failed for user 'HOME\598'.

public class UsersDb : DbContext
{
    public DbSet<BE.User> users { get; set; }
}
david
  • 1
  • 3

2 Answers2

0

Set the user on your application pool to "Local System". It has admin rights, it might be able to open the DB.

Johnny5
  • 6,664
  • 3
  • 45
  • 78
0

may be the service user not have access to database, for testing you can pass user name and password in connection string

<add name="UsersDb"
       connectionString="Data Source=(LocalDB)\v11.0;
       initial catalog=UsersDb;
                 AttachDbFilename=|DataDirectory|C:\Users\X7\Desktop\MyProject\DAL.UsersDb.mdf;
                 user id=user;password=pass;  MultipleActiveResultSets=True;  App=EntityFramework"
       providerName="System.Data.SqlClient" />

And in deployment you can save the username and password in code and change connection string in code

code supply the password to a connection string

Community
  • 1
  • 1
Jophy job
  • 1,924
  • 2
  • 20
  • 38
  • still not work, Is there a guide or something that explains how to associate a data base To another location, it should be apparent very simple – david Sep 05 '15 at 22:32
  • what is the connection string that used for debugging ? – Jophy job Sep 05 '15 at 22:39
  • @david i got this link can you try this http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-2-instance-ownership.aspx – Jophy job Sep 05 '15 at 22:49