ASP.NET MVC 无法使用 SqlConnection 连接到数据库

发布于 2024-12-11 22:07:42 字数 675 浏览 0 评论 0原文

我正在尝试创建一个连接到我只有读取访问权限的第三方 Oracle 数据库的 MVC 站点。这是我第一次使用 MVC 和 Razor,因此我在根文件夹中创建了一个 ASPX 页面来帮助调试和验证我的数据。

现在我只是尝试在我的视图之一中显示查询中的数据。我用过这个 示例 作为连接到模型中的数据库的指南。在我的调试 ASPX 页面中,我创建了一个 GridView,并将 SqlDataSource 设置为相同的连接字符串和查询。

GridView 显示数据没有任何问题,但是当我尝试转到视图时,当它到达连接的打开命令时,出现以下错误:

与 SQL Server 建立连接时发生网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)

GridView 的 SqlDataSource 连接到数据库的方式有什么不同,以及如何在我的模型中复制它?

I'm trying to create an MVC site that connects to a third-party Oracle DB for which I only have read access. This is my first time using MVC and Razor, so I created an ASPX page in the root folder to help with debugging and verifying my data.

Right now I'm just trying to display data from a query in one of my views. I used this example as a guide for connecting to the DB in the model. In my debug ASPX page, I created a GridView with the SqlDataSource set to the same connection string and query.

The GridView displays the data without any issue, but when I try to go to the View, I get the following error when it reaches the connection's Open command:

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)

What is different about the way the GridView's SqlDataSource is connecting to the DB, and how can I replicate that over in my model?

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

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

发布评论

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

评论(1

寂寞笑我太脆弱 2024-12-18 22:07:42

如果您要连接到 Oracle,则不想使用 SqlConnection,您需要使用这些的 oracle 版本。

http://msdn.microsoft.com/en-us/library/ms973871.aspx

If you're connecting to Oracle, you don't want to use SqlConnection, you need to use the oracle versions of these.

http://msdn.microsoft.com/en-us/library/ms973871.aspx

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