如何使用 datacontext 将 ASP.NET MVC 站点发布到外部 SQL Server?

发布于 2024-08-02 12:20:38 字数 716 浏览 2 评论 0原文

我正在使用 MVC,并制作了一个简单的网站。我有一台运行 SQL Server Express 的独立计算机,上面有一个名为“Log”的简单表。该表具有 ID、时间戳和消息字段。我将数据库添加到“服务器资源管理器”部分的“数据连接”中。

在我的 MVC 网站中,我创建了一个新的 LINQ to SQL 类,并将日志表拖到创建数据上下文的设计界面。

因此,我将完成剩下的工作,使用 LINQ 获取数据,将其传递到视图,然后循环遍历它。当我在本地运行它时,效果很好。但是,当我将其发布到 IIS 服务器时,出现以下错误。

Server Error in '/' Application.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

所以看起来它找不到服务器。我该如何解决这个问题?

I am playing with MVC and I made a simple site. I have an seperate machine running SQL Server Express and on it I have a simple table called "Log". The table has ID, Timestamp, and Message fields. I added the database to my "Data Connections" on my "Server Explorer" section.

In my MVC website I created a new LINQ to SQL class and dragged the Log table to the design surface which created the datacontext.

So I do the rest, get the data using LINQ, pass it to the view, and loop through it. This works fine when I run it locally. However, when I publish it to our IIS server it gives me the following error.

Server Error in '/' Application.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

So it seems that it can't find the server. How do I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2024-08-09 12:20:38

您的 IIS 服务器是否可以访问您的 Sql Server Express?

Does your IIS server has access to your Sql Server Express?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文