1

I am trying to run an application that has been downloaded from GitHub. The creator of the project provided usernames and passwords to log in for the application. Whenever I try to log in, I get an error that says:

"System.Data.SqlClient.SqlException: 'Cannot open database "Library" requested by the login. The login failed. Login failed for user 'DESKTOP-CBKOJI6\user'."

I tried doing the following but I still keep getting the same error

Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET'

<connectionStrings>
name="DbConnection"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Library;Integrated Security=TrueConnect; Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
</connectionStrings>

This is the database that is in the App.config

The error I get is in this line of code:

con.Open();

EDIT 1:

Link for the project >> https://github.com/RuXeR97/Library

F.A
  • 297
  • 1
  • 3
  • 13

2 Answers2

1

You have to actually create the database first... You can't log into it if it doesn't exist.

Did the download come with a database project (you can publish that through visual studio), or .sql files (you can run them in SQL Server Management Studio) to create the database first.

Maybe link to the github project so we can take a look?

Milney
  • 6,253
  • 2
  • 19
  • 33
  • I added the URL. The thing is I do not know how to set up the database (if I need to) – F.A Apr 10 '19 at 22:02
  • Yes you do need to - The folder Database has the database files (.mdf and .ldf) in it - you need to attach those to your LocalDb SQL Instance, or change the connection string to point directly to the file. There are many guides on this: http://thedatafarm.com/data-access/attaching-an-mdf-database-to-localdb-in-visual-studio-the-easier-way/ or https://stackoverflow.com/questions/27564279/what-is-the-best-way-to-attach-existing-database-to-sql-localdb – Milney Apr 10 '19 at 22:03
  • So should I just add the path to the connection string in the App.Config like the solution in the stackoverflow link? – F.A Apr 11 '19 at 01:23
1
Data Source=(localdb)\MSSQLLocalDB;

According to this line of code, you are trying to log into a local database which is supposed to be created by yourself locally. If the Github author already created a database on server and provided you with credentials, then all you have to do is to update this localDB server by the server name he provided in Github page.

Verse He
  • 97
  • 9