1

i try to modify my local db connection (which works fine) in the appsettings.json :

 "ApplicationDbContextConnection": "Server=(localdb)\\mssqllocaldb;Database=CateringMilano;Trusted_Connection=True;MultipleActiveResultSets=true"

with the sql server connection :

 "ApplicationDbContextConnection": "Data Source=SQL5101.site4now.net;Initial Catalog=db_9b307b_cateringmilano;User Id=db_9b307b_cateringmilano_admin;Password=YOUR_DB_PASSWORD;Trusted_Connection=True;MultipleActiveResultSets=true"

but when i run the project i got a strange error:

local host does not exists..

and also

An unhandled exception occurred while processing the request.

SqlException: Failed to generate SSPI context. Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, bool breakConnection, Action wrapCloseInAction)

and also i cannot see the sql server db in visual studio sql explorer..

What do i need to connect my website to my sql sever db? what am i missing to do?

Thanks

1
  • Hello Tamil, did you able to made any progress on it? Let us know how its going on. Commented Feb 11, 2022 at 2:14

3 Answers 3

2

It seems you want to connect your remote hosting SQL server instance with your application instead of location database instance. If that is the scenario then your database connection string should like below:

When used in web.config file:

data source=SQL5101.site4now.net;initial catalog=db_9b307b_cateringmilano;User Id=db_9b307b_cateringmilano_admin;Password=YOUR_DB_PASSWORD;integrated security=False;Trusted_Connection=False;MultipleActiveResultSets=True; />

When used in appsettings.json:

"ConnectionStrings": {

    "DefaultConnection": "Server=SQL5101.site4now.net;Database=db_9b307b_cateringmilano;User Id=db_9b307b_cateringmilano_admin;Password=YOUR_DB_PASSWORD;integrated security=False;Trusted_Connection=False;MultipleActiveResultSets=True;"
  }

enter image description here

When used in Ado.net connection string file:

  using (var connection = new SqlConnection("Server=SQL5101.site4now.net;Database=db_9b307b_cateringmilano; User Id=db_9b307b_cateringmilano_admin;Password=YOUR_DB_PASSWORD;integrated security=False;Trusted_Connection=False;MultipleActiveResultSets=True;"))
            {
             

            }

Tips to check if the connection successful :

  • Go to your SQL Server Managament Studio and click on below tab:

enter image description here

  • Then enter your remote SQL server credential like below:

enter image description here

If the connection is alright you should get following:

enter image description here

It means that you have successfully able to connect. So try above steps I have provided.Hope that would guide you accordingly.

Note:

Trusted_Connection=false also allow you connect the database from your SQL server hosting provider But as you are accessing with your server credential you can set that to Trusted_Connection=true.

Feel free to share if you have any further concern on it.

Sign up to request clarification or add additional context in comments.

Comments

0

since you are using userid and password for your new server, replace

Trusted_Connection=True;

with

Integrated Security=False;

Comments

0

Are you be able to connect SQL remotely? If it is working, then please double check your connection string or you can ask your provider about correct connection string that you need to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.