回答編集履歴
1
動作するソースを追記
answer
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
`ConfigurationManager`ではなく、`WebConfigurationManager`を使うのかな?
|
2
2
|
以下のページにサンプルがありますので、見てみてください :D
|
3
3
|
|
4
|
-
参考: [How to: Read Connection Strings from the Web.config File](https://msdn.microsoft.com/en-us/library/ms178411.aspx)
|
4
|
+
参考: [How to: Read Connection Strings from the Web.config File](https://msdn.microsoft.com/en-us/library/ms178411.aspx)
|
5
|
+
|
6
|
+
|
7
|
+
-- 追記
|
8
|
+
|
9
|
+
Web.config (`connectionString`は変更してください)
|
10
|
+
```xml
|
11
|
+
<?xml version="1.0" encoding="utf-8"?>
|
12
|
+
<configuration>
|
13
|
+
<connectionStrings>
|
14
|
+
<add name="DefaultConnection" connectionString="..." />
|
15
|
+
</connectionStrings>
|
16
|
+
</configuration>
|
17
|
+
```
|
18
|
+
|
19
|
+
```csharp
|
20
|
+
using System.Web.Configuration;
|
21
|
+
string ConectionStr = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
|
22
|
+
```
|