0

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 :)

Community
  • 1
  • 1
Bilal Ahmed
  • 1,043
  • 4
  • 17
  • 32
  • Did you recreate the database in the new machine, or you trying to access the SQL that is in your office from your home? The windows authentication means that you have to have the user on the new machine, try to use SQL server authentication. – Flávio Filho Jan 24 '16 at 14:54
  • 1
    Make the `Integrated Security=True` – Mahbubur Rahman Jan 24 '16 at 14:56
  • do you have sql server management studio at home? – IndieTech Solutions Jan 24 '16 at 15:06
  • I'm not using management studio, I'm using visual studio's local platform for accessing database through server explorer @Alundra – Bilal Ahmed Jan 24 '16 at 15:15
  • So, how do I create a user on my new machine that have access to SQL database? @FlávioFilho – Bilal Ahmed Jan 24 '16 at 15:18
  • right click on your DB in VS -> new query and run this `exec sp_addrolemember 'db_owner', 'user'; GO` this command will give `user` owner access to your DB. If the password is the issue try to reset it with this command 'ALTER LOGIN user WITH PASSWORD = '';' – IndieTech Solutions Jan 24 '16 at 15:25
  • @Alundrathedreamwalker , it is still giving me the same error even for the new query – Bilal Ahmed Jan 24 '16 at 15:33
  • Yes, I've tried it already – Bilal Ahmed Jan 24 '16 at 15:40
  • right click on your database and check you connection string https://unsee.cc/zimotune/ and use that connection string instead – IndieTech Solutions Jan 24 '16 at 15:43
  • @BilalAhmed, Please check whether the below post can help you: http://stackoverflow.com/questions/27826245/i-cant-get-a-sql-server-localdb-connection-to-work-on-a-computer-that-does-not – Bala Sakthis Jan 24 '16 at 17:37
  • Have a look at this post on CodeProject. http://www.codeproject.com/Tips/775607/How-to-fix-LocalDB-Requested-Login-failed – jvanrhyn Jan 24 '16 at 18:50

1 Answers1

0

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..

Bilal Ahmed
  • 1,043
  • 4
  • 17
  • 32