gpt4 book ai didi

c# - 无法连接到 LINQ to SQL 网页上的 SQL 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:56 25 4
gpt4 key购买 nike

在我的生产服务器上,我有 2 个 SQL Server 实例,SQL Server 2000 是默认实例,我有\SQLEXPRESS2008 作为附加命名实例。在我的 Web 项目中,我需要连接到默认的 SQL 2000 实例。

我在 Visual Studio 2008 中使用 LINQ to SQL。

在 Visual Studio 的服务器资源管理器中,我可以创建到数据库的连接、查看所有表、正确生成 LINQ to SQL 类等。

在 Management Studio 中,我可以连接到数据库、查看所有内容、进行编辑等。

但是,当我尝试运行我的 Web 项目代码时,我得到:

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)

我在 Web 项目中的连接字符串如下所示:

<add name="myConnectionString" connectionString="Data Source=myServer.com;Initial Catalog=myDB;Persist Security Info=True;User ID=sa;Password=XXXXX" providerName="System.Data.SqlClient" />

(出于绝望,我正在使用 sa 帐户进行测试)。

我还有其他运行良好并利用数据库的 Web 项目,但这是唯一一个使用 LINQ to SQL 类的项目(如果重要的话)

感谢帮助

乔纳森

最佳答案

如果web server和sql server一样,就用.作为服务器名;简单多了。

如果 Web 服务器使用的与 SQL 服务器相同,请确保这些服务器之间通过任何防火墙等保持可见。还要确保服务器名称解析(在许多方式,如果不能保证名称解析,在连接字符串中使用 IP 地址更简单。

关于c# - 无法连接到 LINQ to SQL 网页上的 SQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4222381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com