Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: connecting to their DB
09-03-2004, 05:55 PM #1
- Join Date
- Apr 2004
- Thanked 0 Times in 0 Posts
connecting to their DB
here the situtation:
-I have the clients asp pages that links to their database.
-They gave me a copy of their DB as an Access file
--Now I need to run a couple of queries to check my pages from my server, how do I connect to my DB without rewriting their code(or change it as little as possible) because after the client aproves the page they put it back on their server, with the old path to connect to their DB
<object id="objCONN" Progid="ADODB.Connection" Runat="server">
<object id="rs1" Progid="ADODB.Recordset" Runat="server">
<object id="objRS2" Progid="ADODB.Recordset" Runat="server">
sql1 = "SELECT i, school, date_start, career_fair FROM recruiting_calendar ORDER BY date_start DESC"
objRS1.CursorType = 2
objRS1.source = sql1
objRS1.ActiveConnection = objCONN
???sorry if this sounds like a newbie question but I am a newbie???
any help or direction would be great
09-04-2004, 05:59 PM #2
- Join Date
- Dec 2002
- Arlington, Texas USA
- Thanked 8 Times in 8 Posts
The best method for this is to store the connection string on another page. Then when you need to use the connection string you would simply use an include file to get it. This way you only have one page to change. on a small site with only a couple pages it isnt a problem to change the connection string on each page but when you work on a large site with hundreds of pages it is a pain to do so on each one. In this example i have named the page dbpath.asp and it will show where the database is located on the server. Which in this instance is a directory named Database inside the inetpub directory but outside of the wwwroot directory
Also I would get rid of the object tags and handle the creation of the objects inside the script delimeters. This way you can clear them from memory when you are done using them.Code:<% Dim myConnectionString, dbPath dbPath = dbPath = "d:\inetpub\Database\" myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbPath & "myAccessDatabase.mdb; Jet OLEDB:Database
use this instead
An even more efficient way is to dump the recordset object and just use the connection object's execute method to get your results.Code:<!--#include file="dbpath.asp"--> <% dim objConn, sql1, objRs1 Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open myConnectionString sql1 = "SELECT i, school, date_start, career_fair FROM recruiting_calendar ORDER BY date_start DESC" Set objRs1 = Server.CreateObject("ADODB.Recordset") objRs1.Open SQL, objConn, 2, 3 If Not objRs1.BOF And Not objRs1.EOF Then 'display your results End If 'remember to close and release the objects from memory when done using them objConn.close Set objConn = Nothing objRs1.close Set objRs1 = Nothing %>