この手順で取得するもの
以下のようなSQL Serverの接続文字列を取得する。
Data Source=localhost\SQLEXPRESS;Initial Catalog=sampleDB;Integrated Security=True
手順
[プロジェクト]-[新しいデータソースの追加]
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_001.png)
「データベース」を選択し「次へ」をクリック
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_002.png)
「データセット」を選択し「次へ」をクリック
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_003.png)
「新しい接続」をクリック
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_004.png)
各情報を設定し「OK」をクリック
データソース名
Microsoft SQL Server (SqlClient)
サーバー名
サーバー名(サーバーのPC名\インスタンス名)
認証
今回は「Windows 認証」とする
データベース名の選択または入力
データベース名
※「テスト接続」をクリックしSQL Serverへ接続可能か確認する
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_009.png)
「アプリケーションに保存する接続文字列を表示」にチェックを入れ、接続文字列をコピーする
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_010.png)
「キャンセル」をクリックしてウィザードを閉じる
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_011.png)
結果
SQL Serverの接続文字列を取得できた!
取得した接続文字列は、C#プログラムでSQL Serverへ接続する際に使用する。
![](https://it-skill-memo.work/wp-content/uploads/2020/07/csharp_connectstr_008.png)