人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

在config.web中保存數據庫連接串

在config.web中保存數據庫連接串

更新時間:2022-09-21 文章作者:未知 信息來源:網絡 閱讀次數:

在asp中有多種方法保存數據庫連接串,asp+提供了另一種新方式:config.web。quickstart中的許多demo都是直接將連接串寫在程序中。這對于demo用途是沒有問題,但在實際使用中是不行的。

本文示范如何使用config.web來存儲連接串。在每頁asp.net中你只需用
調出來就可以直接使用了。這樣做的好處一是安全,二是方便,改密碼時只需改一個地方即可。

廢話少說,這里就是code:(放在該application的根目錄下)

Config.web
<configuration>
        <appsettings>
                <add key="MyConn" value="server=localhost;uid=sa;pwd=mypassword;Database=somedatabase"/>
        </appsettings>
</configuration>


Somepage.aspx
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>

<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)

'This is the meat of calling the DSN out of the config.web

'Setting a local variable to hold the connection string variable
Dim MyConnection As SQLConnection
Dim Config as HashTable

'Setting a local variable to hold the connection string
Config = Context.GetConfig("appsettings")
MyConnection = New SQLConnection(Config("MyConn"))

'Setting a command object to insert some data into a database
Dim MyCommand As SQLCommand

dim parm1 as string = "SomeTextValue"
dim parm2 as string = "SomeTextValue2"

Dim InsertCmd As String = "Insert into tablename values (@parm1, @parm2)"

'Using the connection string
MyCommand = New SQLCommand(InsertCmd, MyConnection)

MyCommand.Parameters.Add(New SQLParameter("@Parm1", SQLDataType.VarChar, 50))
MyCommand.Parameters("@Parm1").Value = Parm1

MyCommand.Parameters.Add(New SQLParameter("@Parm2", SQLDataType.VarChar, 50))
MyCommand.Parameters("@Parm2").Value = Parm2

MyCommand.ActiveConnection.Open()
MyCommand.Execute()
MyCommand.ActiveConnection.Close()

End Sub
</script>




溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 梅河口市| 阳谷县| 呼图壁县| 裕民县| 曲水县| 蛟河市| 台南市| 谢通门县| 黄平县| 类乌齐县| 田东县| 广昌县| 许昌市| 黎城县| 桐梓县| 平原县| 南宁市| 齐齐哈尔市| 莱芜市| 开原市| 昆山市| 苍山县| 滁州市| 江北区| 于田县| 双城市| 科尔| 博乐市| 嘉定区| 东阿县| 锡林浩特市| 财经| 卓资县| 城口县| 达日县| 扶绥县| 东至县| 边坝县| 龙口市| 蚌埠市| 衡阳市|