How to Configure a string Connection

Asked

Viewed 157 times

-2

I am wanting to connect to the database but my string Connection is not starting.

Error: https://prnt.sc/ngeqde

Class Startup:

var connectionString = this.Configuration.GetConnectionString("PokemonBD");

services.AddTransient<IDataBaseContext>(contex => 
    new DatabaseContext(new SqlConnection()));

services.AddTransient<IpokemonRepository, PokemonRepository>();

Appsetting.Development.json

 "ConnectionString": {
    "PokemonBD": "Server=tcp:****.database.windows.net,1433;Initial Catalog=DbPokemon;Persist Security Info=False;User ID=****;Password=****;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}
  • Permission not accepted, seems user and password wrong

  • Not using the same ID and Pass to connect to Azure Data Studio

  • services.AddTransient< IDataBaseContext >(contex => new DatabaseContext(new SqlConnection(connectionString ))); try like this

  • I’ve done it, it didn’t work

  • class: DatabaseContext

  • You did, but another problem came up, but thank you very much

Show 1 more comment

1 answer

2


Failed to pass the pro connection string SqlConnection.

var connectionString = this.Configuration.GetConnectionString("PokemonBD");

services.AddTransient<IDataBaseContext>(contex => 
     new DatabaseContext(new SqlConnection(connectionString)));

services.AddTransient<IpokemonRepository, PokemonRepository>();
  • I just passed, but the problem is still

  • @B.Martins The problem continues or is another mistake?

  • I solved this problem, I moved from Idatabasecontext to Databasecontext, even so thank you.

  • @B.Martins I understood it was nothing, but anyway. If the answer helped you can mark it as correct using the V on the left side

Browser other questions tagged

You are not signed in. Login or sign up in order to post.