10
私はASPファイルを持っています。実際に私はファイル内のconnectionStringを使ってDataBaseに接続します。ASP.ClassicのWeb.ConfigからConnectionStringを読み取る
sConnString = "Driver={SQL Server}; Server=localhost; Database=DB"
Web.ConfigからConnectionStringを読み取る方法はありますか?
EDIT:
はそれがで動作するようになった:
' Imports a connection string from an xml file (usually web.config)
Function ImportConnectionString(webConfig, attrName, reformatDSN)
Dim oXML, oNode, oChild, oAttr, dsn
Set oXML=Server.CreateObject("Microsoft.XMLDOM")
oXML.Async = "false"
oXML.Load(Server.MapPath(webConfig))
Set oNode = oXML.GetElementsByTagName("connectionStrings").Item(0)
Set oChild = oNode.GetElementsByTagName("add")
' Get the first match
For Each oAttr in oChild
If oAttr.getAttribute("name") = attrName then
dsn = oAttr.getAttribute("connectionString")
If reformatDSN Then
' Optionally reformat the connection string (adjust as needed)
dsn = Replace(dsn, "User ID=", "UID=")
dsn = Replace(dsn, "Password=", "PWD=")
dsn = Replace(dsn, "Data Source=", "Server=")
dsn = Replace(dsn, "Initial Catalog=", "Database=")
dsn = Replace(dsn, "Persist Security Info=True;", "")
dsn = "Provider=MSDASQL;Driver={SQL Server};" & dsn
End If
ImportConnectionString = dsn
Exit Function
End If
Next
End Function
使用法:ちょうど助け
ありがとうございました – Paks
私はまた、[このページ](http://www.c-sharpcorner.com/UploadFile/sd_patel/WebConfigInASPNet11242005061608AM/WebConfigInASPNet.aspx)から、接続文字列をweb.config – mfeineis
@vanhelgenあなたがリンクしているページは、彼の答えに記述されているwebawareを正確に実行しています。 – crush