简体   繁体   English

将ASP.Net应用程序从Web连接到计算机上的sql数据库

[英]Connect ASP.Net application from web to my sql database on my computer

I am creating two applications: An ASP.Net application and a C# application. 我正在创建两个应用程序:一个ASP.Net应用程序和一个C#应用程序。 I used SQL Server as the database. 我使用SQL Server作为数据库。 My ASP.Net application should connect to the internet but the database should only be on my computer. 我的ASP.Net应用程序应该连接到Internet,但是数据库只能位于我的计算机上。 I used connectionString to connect my two applications in just one database (SQL). 我使用connectionString在一个数据库(SQL)中连接两个应用程序。 Is there a way to connect my ASP.Net application from the web to my SQL database on my computer? 有没有一种方法可以将我的ASP.Net应用程序从Web连接到计算机上的SQL数据库?

I've read lots of tutorial but I can't find the solution. 我已经阅读了很多教程,但是找不到解决方案。

Ordinary SQL Server is local to to the Web application (it's either located on the same LAN or sometimes even on the same machine). 普通SQL Server对Web应用程序而言是本地的(它位于同一LAN上,有时甚至位于同一台计算机上)。

Technically it is possible to connect an ASP.NET application to a remote SQL server, but it is not recommended, you can open a can of worms there (problems with firewalls, ports, performance etc.) 从技术上讲,可以将ASP.NET应用程序连接到远程SQL Server,但是不建议这样做,您可以在其中打开蠕虫病毒(防火墙,端口,性能等问题)。

Here's my solution for that: 这是我的解决方案:

  1. Make sure you have a static IP address assigned by the ISP. 确保您有一个由ISP分配的静态IP地址。
  2. Make sure that you assign a static IP address in your computer. 确保在计算机中分配了静态IP地址。
  3. Now, use "Port Forwarding" technique. 现在,使用“端口转发”技术。 Configure your router to forward the packets from port 1433 going to your computer. 配置路由器以将来自端口1433的数据包转发到计算机。
  4. The next thing you do is you configure or modify your web.config (ASP.NET file) that is deployed outside your network (in a hosting company) and make sure that the datasource of your connectionString looks something like this: connectionString="data source=214.23.12.21 (where 214.23.12.21 is the static public IP assigned to you by your ISP). 接下来要做的是配置或修改在网络外部(在托管公司中)部署的web.config(ASP.NET文件),并确保connectionString的数据源如下所示:connectionString =“ data source = 214.23.12.21(其中214.23.12.21是ISP分配给您的静态公共IP)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一台计算机上运行我的asp.net Web应用程序以及我的SQL数据库 - How to run my asp.net web application on another computer along with my SQL database Unable to connect to Azure SQL database from my ASP.NET Core Web API application but able to connect to db from Management Studio - Unable to connect to Azure SQL database from my ASP.NET Core Web API application but able to connect to db from Management Studio ASP.Net Web应用程序连接到主机SQL数据库 - ASP.Net web application connect to host SQL DataBase 从asp.net应用程序连接到SQL Server数据库 - connect to sql server database from asp.net application 与我的ASP.NET Web应用程序的多个SQL Server连接 - Multiple SQL Server connection to my ASP.NET web application 无法从我的 ASP.Net 项目上的 VS2019 连接到 SQL 服务器数据库 - Cannot connect to SQL Server database from VS2019 on my ASP.Net project 从我的asp.net mvc Web应用程序调用asp.net控制台应用程序 - Calling an asp.net console application from my asp.net mvc web application 如何连接到ASP.NET Web应用程序中的MySql数据库? - How to connect to a MySql database in ASP.NET web application? 当我从另一个用户运行我的 ASP.NET Core MVC 解决方案时,它没有连接到 SQL Server 数据库 - When I run my ASP.NET Core MVC solution from another user it does not connect to the SQL Server database 检索/获取数据以从连接到远程MySQL数据库的PHP服务显示到我的ASP.Net Web应用程序 - Retrieve/fetch data to display to my ASP.Net web application from PHP service thats connected to remote MySQL database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM