当我使用没有连接字符串的服务器资源管理器时如何在客户端系统中安装我的应用程序

时间:2013-03-23 05:59:22

标签: c# linq-to-sql database-connection server-explorer

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

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>

1 个答案:

答案 0 :(得分:0)

导致此错误的原因是dbml文件中的表来自不同的数据库,connection string中的app.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中提到的数据库名称。