如何使用 datacontext 将 ASP.NET MVC 站点发布到外部 SQL Server?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 IIS 服务器是否可以访问您的 Sql Server Express?
Does your IIS server has access to your Sql Server Express?