i have the next problem, im doing a college work and my teacher ask to integrate the database directly on my proyect, the idea behind this is to export the proyect and be able to excecute the page without modifications in other pc/laptop, my page directory looks like this right now
WebApplication1
| Connected Services
| Dependencias
| Properties
| wwwroot
| Data
| | dataBaseHelper.cs
| | MyDb.mdf
| Pages
| appsettings.json
| Program.cs
i tried to put this line to connect it on my appsetting.Development.json
"DefaultConnection": "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Data\MyDb.mdf;Integrated Security=True;Connect Timeout=30"
but it doesn’t work, it shows this error
An unhandled exception occurred while processing the request.
ArgumentException: Invalid value for key ‘attachdbfilename’.
System.Data.SqlClient.SqlConnectionString..ctor(string connectionString)
and my connection string use that DefaultConnection
public DatabaseHelper(IConfiguration configuration) { _connectionString = configuration.GetConnectionString("DefaultConnection"); }
i tried using other ways to conncet it based on some research y made, using this connection for example
"DefaultConnection": "Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True;Connect Timeout=30"
and it shows this other error
SqlException: Cannot open database “MyDb” requested by the login. The login failed.
Login failed for user ‘DESKTOP-H14KUICnicol’.
naxtronix mortivus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.