Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database calls & Includes...

Status
Not open for further replies.

WhiteTiger

Programmer
Jun 26, 2001
605
US
Ok, I'm not good at ASP at all...never worked with it, anything, but I do learn quick, so help me here...:p

so far I have this:

<%@ LANGUAGE = VBScript %>
<%
Response.Expires=0
pnum=request(&quot;pnum&quot;)
Set cn1 = server.CreateObject(&quot;adodb.connection&quot;)
Set rs1 = server.CreateObject(&quot;adodb.recordset&quot;)
cn1.Provider = &quot;MSDASQL&quot;
cn1.ConnectionString = &quot;driver={SQL Server};server=faid-s00;userid=forum;pwd= &quot;
cn1.Open
cn1.DefaultDatabase = &quot;advantage&quot;
rs1.Open &quot;SELECT prprincipal, prprojmgr, prclient, prselect1 FROM PR WHERE substring(prProject,2,4)='&quot; & request(&quot;pnum&quot;) & &quot;'&quot;, cn1, 1, 3
if rs1(&quot;prprincipal&quot;)=&quot;00009&quot; then
prin=&quot;James B. Black&quot;
else
prin=&quot;R. Norman Stoehr&quot;
end if

Whenever I try to put anything after PNUM=request, to rs1.open, it errors out on the page...is there any way to put that database access part within an include file?
 
WhiteTiger,

I am looking at the line pnum=request(&quot;pnum&quot;)...Is this coming from a form? Don't you want request.form(&quot;pnum&quot;)?
You do the same thing in the sql statement too.

As for putting it in an include. Sure you can. Open your connection, your recordset your command object...I wouldn't open your sql command though. Do that in each separate page. Hope that helps and someone correct me if I am mistaken.

Mike
 
personally, I have a site that I have too many pages with connections to put in every page, so I have an include. But would not be wise to put sql statements in there, actually impractical, as the sql statement will be dynamic to the page that you are currently working with. I personally also open the recordset on each page because I may only have one rs on one page, but might of 2 or 3 on another page at one time.

---connect.asp---------------------------------

<%
Dim conn, DSNtemp
Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
DSNtemp = &quot;DRIVER={Microsoft Access Driver(*.mdb)};&quot;
DSNtemp = DSNtemp & &quot;DBQ=C:\InetPub\ conn.Open conn
%>

-----------------------------------------------


---MainPage.asp--------------------------------

<!-- #include file=&quot;connect.asp&quot; -->
<%
Dim rs, sql
sql = &quot;SELECT * FROM myTable;&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, conn, 3, 3

Response.write(&quot;Hello &quot; & rs(&quot;firstName&quot;) & &quot;...&quot;)

rs.Close
conn.Close
Set rs = nothing
Set conn = nothing
%>

=========================================================

Hope this answers your question...
-Ovatvvon :-Q
 
thanks guys, the problem I was having was it was VBScript...and I had forgot to put the stupid tags in the include...lol

I got it down though...

The reason were doing this is because sometimes, the database or server changes, and we need to be able to just take the include, change that information, instead of going to all of the pages, and changing all of the information by hand...now, there are like 20 pages that the database information is linked to the include...=) When life gives you lemons...throw them back and get the oranges you ordered! :-Q
 
HeeHee...
Think I have over 200 pages useing the single include of db connection.
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top