0

我已经添加了一个 Linq to Sql 类,并且在服务器探索中我已经在我的系统中附加了我的 sql 服务器名称和数据库。app.Config 文件中自动创建了一个连接字符串。除此之外,我没有在任何地方写任何连接字符串。我正在创建 DataContext 类对象并使用我的数据库中的数据。

数据上下文类

 DtContext.purchasesDtlsDataContext purchasesDC = new slsandPchsLib.DtContext.purchasesDtlsDataContext();

从数据库中检索数据

 var goods = from gds in purchasesDC.goodsrcpts_rd(Id) select gds;
 var goodsDtls = from dtls in purchasesDC.goodsrcptsdtls_rd(Id) select dtls;

因为这我在我的电脑上做得很好。现在我正在尝试在另一台(客户端)计算机上使用我的应用程序。我已将我的数据库附加到 sqlServer 并更改了 App.Config 文件 DataSource 中的服务器名称。我仍然无法连接到数据库。我收到一个错误

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

我该如何解决我的问题

我在 app.config 中的连接字符串是 ....

  <connectionStrings>
    <add name="slsandPchsLib.Properties.Settings.SalesPrchsConnectionString"
        connectionString="Data Source=CENSYS07\SQLEXPRESS;Initial Catalog=SalesPrchs;Integrated Security=True"          
        providerName="System.Data.SqlClient" />
</connectionStrings>
4

1 回答 1

0

导致此错误的原因是您的dbml文件中的表来自不同的数据库并且您的connection stringinapp.config属于不同的数据库。

请检查您的数据库归属于您的connection string in app.config file.

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

您可能知道发生此错误是因为系统无法找到您在 app.config 中提到的数据库名称。

于 2013-03-23T06:02:44.403 回答