Linq を Sql クラスに追加し、サーバー エクスプローラーでシステムに SQL サーバー名とデータベースをアタッチしました。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>