Klasik Asp ile Asp.Net web.config connection stringe erismek
Şubat 6, 2009 at 6:31
—
Hayati GÜNEY
Asp.Net ve Asp ile hybrid bir proje gelistiriyorsanız ya da Asp.net ile gelistirilmis bir uygulamanin kullanmakta oldugu veri tabanina erismek istiyorsaniz, connectionString'i web.config dosyasında bu yöntemle çekebilirsiniz.
Örnek web.config Dosyamız :
<?xml version="1.0"?>
<configuration>
<configSections>[...]</configSections>
<appSettings/>
<connectionStrings>
<add name="DataConnectionString" connectionString="Data Source=SqlServerName;Initial Catalog=SqlDatabaseName;Persist Security Info=True;User ID=DatabaseUser;Password=Password" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>[...]</system.web>
<system.codedom>[...]</system.codedom>
<system.webServer>[...]</system.webServer>
<runtime>[...]</runtime>
</configuration>
ConnectionStringi Yakalayacak Olan Asp Kodumuz:
<%
set xmlDoc=server.CreateObject("Microsoft.XMLDOM")
set xmlconnectionStrings=server.CreateObject("Microsoft.XMLDOM")
set xmladd=server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
' Web.config dosyasının yolunu doğru konfigure edin
xmlDoc.load(server.MapPath ("web.config"))
set xmlconnectionStrings = xmldoc.GetElementsByTagName("connectionStrings").Item(0)
set xmladd = xmlconnectionStrings.GetElementsByTagName("add")
for each x in xmladd
'Attribute için doğru isim ve doğru değer girin
if x.getAttribute("name") ="DataConnectionString" then
'ConnStr değişkenine connection string atanıyor
ConnStr = (x.getAttribute("connectionString"))
response.write ConnStr
end if
next
%>