Forums
This topic is locked
Database Connection Problems
Posted 13 Apr 2006 12:43:11
1
has voted
13 Apr 2006 12:43:11 Mark McElhone posted:
Hi,am working on an asp.net web site in Dreamweaver on a Mac OS X.
I have a problem creating a connection to my Access Database in that I cannot. can someone please help on how to create the connection,
thanks in advance
Mark
Replies
Replied 13 Apr 2006 19:07:41
13 Apr 2006 19:07:41 micah santos replied:
db_Conn.asp
----------------
<%
Dim strConn,objConn
Sub OpenDB
strConn = ""
strConn = strConn & "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn = strConn & "Data Source=" & Server.MapPath("DBASE.MDB" & ";"
strConn = strConn & "Persist Security Info=False"
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open strConn
End Sub
Sub CloseDB
objConn.Close
Set objConn = Nothing
End Sub
%>
whenever you need to open or close you database connection, just call the procedure.
e.g.
registration.asp
---------------------
<!--#include file="db_Conn.asp"-->
<%
Call OpenDB
// rest of the codes here
// when you're done using the database, then, close it.
Call CloseDB
%>
----------------
<%
Dim strConn,objConn
Sub OpenDB
strConn = ""
strConn = strConn & "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn = strConn & "Data Source=" & Server.MapPath("DBASE.MDB" & ";"
strConn = strConn & "Persist Security Info=False"
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open strConn
End Sub
Sub CloseDB
objConn.Close
Set objConn = Nothing
End Sub
%>
whenever you need to open or close you database connection, just call the procedure.
e.g.
registration.asp
---------------------
<!--#include file="db_Conn.asp"-->
<%
Call OpenDB
// rest of the codes here
// when you're done using the database, then, close it.
Call CloseDB
%>
Replied 19 Apr 2006 12:17:00
19 Apr 2006 12:17:00 Mark McElhone replied:
thanks for that but i am not sure where i would put the code and when to use it. Could you maybe elaborate?
Replied 19 Apr 2006 16:33:22
19 Apr 2006 16:33:22 micah santos replied:
assuming that you had this file REGISTRATION.ASP
of course, you need to set up a connection to your database in order to save all the records that has been submitted by the user. by creating INCLUDE FILE, you had minimize the redundancy of using the scripts from different set of pages.
here's how, on the very top of page you need to include this tag -> <!--#include file="DB_CONN.ASP"-->
REGISTRATION.ASP
--------------------------------------------
<!--#include file="DB_CONN.ASP"-->
<%
// Call the procedure that will open the database
Call OpenDB
// and the rest of the codes here
// when you do not the connection anymore, simply close it by calling another procedure
Call CloseDB
%>
by doing this way, instead of writing all the database connection scripts, you'll just have to incorporate the INCLUDE file on top of those pages where it needed most. let's assume you don't want to use the INCLUDE FILE. here's how it looks like.
e.g.
REGISTRATION.ASP
-----------------------------
db_Conn.asp
----------------
<%
Dim strConn,objConn
Sub OpenDB
strConn = ""
strConn = strConn & "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn = strConn & "Data Source=" & Server.MapPath("DBASE.MDB" & ";"
strConn = strConn & "Persist Security Info=False"
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open strConn
End Sub
Sub CloseDB
objConn.Close
Set objConn = Nothing
End Sub
// Now, call the openDB procedure
CALL openDB
// and if you're done, close it
CALL closeDB
%>
however, in most cases dealing database, what if you got TWO (2) databases in your project or there are some instances where you have to close the database and re-open it again to another set of pages? instead of writing the scripts all over again, basically, just incorporate the INCLUDE file whenever you need.
hope this explanation helps. just let me know if any part of this ellaboration you didn't understand and I'll explain it again as best as I can.
regards,
micah
n.1asphost.com/micahsantos
of course, you need to set up a connection to your database in order to save all the records that has been submitted by the user. by creating INCLUDE FILE, you had minimize the redundancy of using the scripts from different set of pages.
here's how, on the very top of page you need to include this tag -> <!--#include file="DB_CONN.ASP"-->
REGISTRATION.ASP
--------------------------------------------
<!--#include file="DB_CONN.ASP"-->
<%
// Call the procedure that will open the database
Call OpenDB
// and the rest of the codes here
// when you do not the connection anymore, simply close it by calling another procedure
Call CloseDB
%>
by doing this way, instead of writing all the database connection scripts, you'll just have to incorporate the INCLUDE file on top of those pages where it needed most. let's assume you don't want to use the INCLUDE FILE. here's how it looks like.
e.g.
REGISTRATION.ASP
-----------------------------
db_Conn.asp
----------------
<%
Dim strConn,objConn
Sub OpenDB
strConn = ""
strConn = strConn & "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn = strConn & "Data Source=" & Server.MapPath("DBASE.MDB" & ";"
strConn = strConn & "Persist Security Info=False"
Set objConn = Server.CreateObject("ADODB.Connection"
objConn.Open strConn
End Sub
Sub CloseDB
objConn.Close
Set objConn = Nothing
End Sub
// Now, call the openDB procedure
CALL openDB
// and if you're done, close it
CALL closeDB
%>
however, in most cases dealing database, what if you got TWO (2) databases in your project or there are some instances where you have to close the database and re-open it again to another set of pages? instead of writing the scripts all over again, basically, just incorporate the INCLUDE file whenever you need.
hope this explanation helps. just let me know if any part of this ellaboration you didn't understand and I'll explain it again as best as I can.
regards,
micah
n.1asphost.com/micahsantos
Replied 19 Apr 2006 16:35:42
19 Apr 2006 16:35:42 micah santos replied:
kindly omit this
db_Conn.asp
----------------
on the last scripts I've shown. it is supposed to be REGISTRATION.ASP only. okay.
db_Conn.asp
----------------
on the last scripts I've shown. it is supposed to be REGISTRATION.ASP only. okay.