[英]Connecting to SQL Server Database using a Hosted Web Application
I have created a .net web application using c# that inserts, updates, and deletes data from an SQL server database. 我已经使用c#创建了一个.net Web应用程序,该应用程序可以从SQL Server数据库中插入,更新和删除数据。 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? 有没有人对如何实现这一目标有任何提示?
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.
如果确实需要进一步的安全保护,则还可以在数据库服务器上为访问此数据的IP设置限制。
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: 如果您的问题是“如何连接另一台服务器上存在的数据库”,则必须在Web.config文件中添加其IP地址,如下所示:
<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. data source
可以是存储数据库的IP地址或PC NAME。
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 您可以将数据库放在同一台计算机上或另一台计算机上。可以选择以下方案
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 解决此问题的最简单方法是使用web.config转换。您要做的就是创建一个新的Web.Release.Config。
Please refer this answer for more details How do I use Web.Config transform on my connection strings? 请参考此答案以获取更多详细信息。 如何在连接字符串上使用Web.Config转换?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.