gpt4 book ai didi

c# - 如何修复错误 "Named Pipes Provider, error: 40 - Could not open a connection to SQL Server"

转载 作者:太空狗 更新时间:2023-10-29 21:15:06 25 4
gpt4 key购买 nike

<分区>

所以我正在尝试制作一个简单的 C# 控制台应用程序,它只查询数据库 - 仅此而已。

但是,我不断收到此错误:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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)

现在,我已经尝试了一切!我已经编辑了我的所有设置(添加了防火墙异常(exception),启用了 TCP/IP,几乎所有你可以通过谷歌搜索找到的解决方案,我都做了)。当我尝试使用连接字符串中的相同凭据使用 SQL Management Studio 建立连接时,一切正常。但是出于某种原因,Visual Studio 没有任何效果。

这是我的连接字符串:

<add name="Invoicing"
connectionString="Data Source=server;Initial Catalog=Invoicing;Persist Security Info=True;ID=id;Password=pw"
providerName="System.Data.SqlClient" />

这是应用程序:

class Program
{
public static void Main(string[] args) {

Invoicing db = new Invoicing("Invoicing");

var q = from sin Invoice
where s.Date == 201007
select s;

foreach(var sin q)
Console.WriteLine("{0}, {1}", s.CreateDate,
s.EndDate);


}
}

这是我的堆栈跟踪:

   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.GetQueryText(Expression query)
at System.Data.Linq.DataQuery`1.ToString()

如果重要的话,我使用 SqlMetal 创建了 DataContext。

此外,我正在使用 .Net 2008 和 SQL 2008。

有没有人知道该怎么做?

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