Two ways for ASP to read a configuration file

Source: Internet
Author: User
Tags readline

Method One: (successfully used in the project)

< head >
< title > Rnnews </title >

< BODY >


<%

' strconnection= ' Driver={mysql ODBC 3.51 Driver}; Server={local};D Atabase=gmdb; User=richman; password=qazwsxedc;option=3; "


strconnection = "driver=" + Getini ("dbconnectstring", "DSN", Server.MapPath ("Ip.ini")) + "; Server= "+ Getini (" dbconnectstring "," Server ", Server.MapPath (" Ip.ini ")) +";D atabase= "+ Getini (" Dbconnect String "," Database ", Server.MapPath (" Ip.ini ")) +"; User= "+ Getini (" dbconnectstring "," User ", Server.MapPath (" Ip.ini ")) +"; Password= "+ Getini (" dbconnectstring "," Password ", Server.MapPath (" Ip.ini ")) +"; option= "+ Getini (" Dbconne Ctstring "," option ", Server.MapPath (" Ip.ini "))
' Response.Write strconnection
' Response.End
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open strconnection
sql = "SELECT * from News where newsflag=1 order by NewsID desc" ' SQL query statement
Set rs = conn.execute (SQL)
If not Rs.bof then
% >

<%
' Do, not rs.eof
Function Getini (Strprimary,strsubkey,strinifilepath)
Set Myfso = Server.CreateObject ("Scripting.FileSystemObject")
Set MyFile = Myfso.opentextfile (Strinifilepath)

Dim intcount
Dim strstate
Do Until Myfile.atendofstream

If intcount = 0 Then
If Myfile.readline = "[" & Strprimary & "]" Then
intcount = 1

End If
Else

Strstate = Myfile.readline
If UCase (left (strstate, Len (strSubKey & =)) = UCase (strSubKey & "=") Then
Getini = Right (Strstate, Len (strstate)-Len (strSubKey & "="))

End If
End If
Loop
Myfile.close
Set MyFile = Nothing
Set Myfso = Nothing
End Function
% >
< p >
<% = RS ("newscontent")% >
</p >
<%
' Rs.movenext
' Loop

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.