1

I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. I have tested it using my localhost and it works fine. Now I would like to publish this application on a hosted site.

My question is, does the database need to be on the same server/host that the application is in for it to connect?
Does anyone have any tips on how to implement this?

5
  • 1
    Is this a project for your personal testing needs? If yes you can try creating a free Azure account and have it all hosted there Commented Nov 28, 2016 at 11:50
  • Hi to make it short: No the database can be anywhere else. But also question like 'Does anyone have any tips on how to implement this?' do not belong on SO. Commented Nov 28, 2016 at 11:51
  • No need for same server/host for database and application. Commented Nov 28, 2016 at 11:51
  • It doesn't have to be on the server but if it is, it often makes connecting a lot easier because you don't have to deal with networks. Take @apomene advice and try out Azure for free Commented Nov 28, 2016 at 12:37
  • thanks for your answers everyone! helped me out for sure! Commented Nov 28, 2016 at 13:34

3 Answers 3

2

No you do not have to run the Database on the same server as the application. For scalability it can be best practice to separate the two, one dedicated server for your DB and one server to host all your websites.

In your application you specify the connection to your Database. On your Database server you can also then set restrictions on the IP to access this data if you really wanted for further security.

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

Comments

1

If your Question is 'How to connect database present on another server', then you have to Add IP address of it in the Web.config file as:

<connectionStrings>
    <add name="myConnectionString" connectionString="data source=myserver\SQLEXPRESS;initial catalog=myDatabase;uid=myUserName;password=myPassword;" />
</connectionStrings>

data source can be IP ADDRESS or PC NAME, where Database is stored.

4 Comments

Thanks for your answer! Yes, so, this is a small application i am doing as a personal project. If I have the Database on my local computer, do I use my IP for the data source to map it to that database?
In this case, you can write server name : "data source=localhost"
even if i am trying to access the database that is located in my local pc, from a hosted web application? Would localhost in the connection string work with that?
nope, it won't! only in a condition where Application and Database both are on the same machine; then only localhost will help, otherwise as per the Answer.
1

does the database need to be on the same server/host that the application is in for it to connect?

It's upto you to put the Database on the same machine or a different machine.You can choose following scenarios

  • If it's a simple website and you only have one Machine,then you can install Database on the same server(or if'ts already present) .In this case the connection string may or may not have to change depending on what type of connection string you use(e.g if your sql server instance name is different,connection string will change)
  • Your website can get complex or process large amount of data,it makes sense to use a dedicated database server .This case connection string will change

Does anyone have any tips on how to implement this?

Easiest way to deal with this is using web.config transformation.All you have to do is create a new Web.Release.Config

Please refer this answer for more details How do I use Web.Config transform on my connection strings?

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.