Search code examples
sql-serverasp.net-mvcvisual-studio-express

Unable to access SQL Server database on a different machine


I'm developing an asp.net mvc application at my office. I wanted to work at home as well, so, I pushed my project on github, when I came my home back, I pulled it from github to my projects folder, now I tried to access its SQL Server database in server explorer using windows authentication, on pressing ok, it showed me the following error :

Cannot open database "HrAndPayrollSystem.Models.HrAndPayroll" requested by the login. The login failed.

Login failed for user 'user'.

and here is my connection string :

<connectionStrings><add name="HrAndPayroll" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=HrAndPayrollSystem.Models.HrAndPayroll;Integrated Security=False" providerName="System.Data.SqlClient" />

What could be the reason, how should I resolve it? Thanks in Advance :)


Solution

  • So, I somehow managed to get through this.

    In other words, this error says that you need to access your database at least for a single time, means you need to perform some transactions with the database, inserting something or retrieving something, at this point you accessed the database for the first time on the different machine. Since, I had to access database at the point when my application starts, so, crashing start crashes my whole application, so I created another controller that does not contain any authorize attribute, just to leave it open in order to access the database, created a single field, accessed the database, now go and check your database in server explorer, you are about to access it for the first time in the database, and now also, it will never crash anywhere.

    So, the point is that you need to access your database at least for a first time..