An include file should be created having following code :
<script language="VBScript" runat="Server">
' Global variables
dim cn ' Connection Object
dim rs ' RecordSet Object
dim rs1,rs2,rs3
sub openCN
set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
set rs1 = Server.CreateObject("ADODB.Recordset")
set rs2 = Server.CreateObject("ADODB.Recordset")
set rs3 = Server.CreateObject("ADODB.Recordset")
cn.OPEN "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("yourdatabasename.mdb") & ";"
'cn.OPEN "SERVER=ipaddressofyourserver;DRIVER={SQL Server};DATABASE=databasename;UID=username;pwd=password;"
end sub
sub closeCN
'close the connection
cn.Close
set rs = Nothing
set rs1 = Nothing
set rs2 = Nothing
set cn = Nothing
end sub
</script>
Now this include file can be included in each ASP page where database access is required. Don't forget to call openCN subroutine.
No comments:
Post a Comment