「web.configで設定した接続文字列を取得」の編集履歴(バックアップ)一覧はこちら
web.configで設定した接続文字列を取得 - (2008/01/21 (月) 15:24:13) の最新版との変更点
追加された行は緑色になります。
削除された行は赤色になります。
*web.configで設定した接続文字列を取得
***概要
web.config中にある「connectionString」を取得する方法
-[[.NET Framework クラス ライブラリ ConfigurationElement.Item プロパティ (String)>>http://msdn2.microsoft.com/ja-jp/library/c8693ks1.aspx]]
//見出し
***前提条件
-[[新しいwebサイトの作成]]
-[[データベースへの接続の追加]]
***手順
web.configに以下を追加。
#highlight(xml){{
<connectionStrings>
<add
name="masterConnectionString1"
connectionString= _
"Data Source=YOKOSAN\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
}}
default.aspx.vbで以下のように取得。
#highlight(vb.net){{
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = System.Configuration.ConfigurationManager.
ConnectionStrings.Item("masterConnectionString1").ToString
End Sub
End Class
}}
Label1をデザインで配置。
#img(113.jpg)
以下のように表示される。
#img(112.jpg)
*&this_page()
**概要
web.config中にある「connectionString」を取得する方法
-[[.NET Framework クラス ライブラリ ConfigurationElement.Item プロパティ (String)>>http://msdn2.microsoft.com/ja-jp/library/c8693ks1.aspx]]
//見出し
**前提条件
-[[新しいwebサイトの作成]]
-[[データベースへの接続の追加]]
**手順
web.configに以下を追加。
#highlight(xml){{
<connectionStrings>
<add
name="masterConnectionString1"
connectionString=
"Data Source=YOKOSAN\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
}}
default.aspx.vbで以下のように取得。
#highlight(vb.net){{
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = System.Configuration.ConfigurationManager. _
ConnectionStrings.Item("masterConnectionString1").ToString
End Sub
End Class
}}
Label1をデザインで配置。
#img(113.jpg)
以下のように表示される。
#img(112.jpg)
表示オプション
横に並べて表示:
変化行の前後のみ表示: