Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2010, 07:49 AM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connection string - Where should I put it?

Hi.

I'm using Windows XP SP3, IIS, SQL Server 2008 and ODBC.

Some say Classic ASP won't work with DNS (ODBC).

So I plan to use 'Connection string' instead.

Where should I put it?

Can you guys help me and show some example?

Kept getting this error;



http://img2.pict.com/cd/8e/ad/3153435/0/800/ptb.jpg




Below is the 'Main.asp' file.

Line 106 refers to the underline bold text below;

Quote:
<%@ Language=VBScript %>

<%
Response.Buffer = True
Response.Expires = -1000
%>

<HTML><HEAD><TITLE>Main Page</TITLE>

<base target="_self">


<BODY bgProperties=fixed bgColor=#FFFFFF leftMargin=0 topMargin=0 bottommargin10>


<DIV style="LEFT: 5px; POSITION: absolute; TOP: 80px"></DIV>

<style type="text/css">
body {font-size: 8pt; font-family: verdana; color:white;}
table, tr, td {font-size: 10pt; font-family: verdana; color: black;}
a:link {font-size: 8pt; font-family: verdana; color:black; text-decoration: none;}
a:visited {font-size: 8pt; font-family: verdana; color:black; text-decoration: none;}
a:active {font-size: 8pt; font-family: verdana; color:#CCCCFF; text-decoration: none;}
a:hover {font-size: 8pt; font-family: verdana; color: #db7093; text-decoration: none;}
<!--A:hover{color:#db7093;text-decoration:underline; cursor:help}-->
font {font-size: 8pt; font-family: arial}
.para1 {position:absolute; top: 48; left: 106; font-family: "font2, Georgia"; font-size: 50px; font-weight:bold; line-height: 40px; text-align: left; color: #CC99FF; }
.para2 {position:absolute; top: 46; left: 105; font-family: "font1, Georgia"; font-size: 50px; font-weight:bold; line-height: 40px; text-align: left; color: #660066; }
.badan1 {font-family: "Verdana"; font-size: 10pt; font-weight:bold; text-align: left; color: #FFFFFF; }
.badan2 {font-family: "Verdana"; font-size: 10pt; font-weight:bold; text-align: left; color: #000000; }
.edit {font-size: 10pt; font-family: symbol; color: #ff1493;}
</style>

<! SCROLLBAR COLOR !>

<STYLE type=text/css>BODY {
SCROLLBAR-FACE-COLOR: #CC99FF; FONT-SIZE: 8pt;
SCROLLBAR-HIGHLIGHT-COLOR: #990099;
SCROLLBAR-SHADOW-COLOR: #CC66FF; COLOR: #000000;
SCROLLBAR-3DLIGHT-COLOR: #9900ff;
SCROLLBAR-ARROW-COLOR: #993366;
SCROLLBAR-TRACK-COLOR:#CC99FF; FONT-FAMILY: arial, trebuchet MS, verdana, arial, sans-serif;
SCROLLBAR-DARKSHADOW-COLOR: #000000
}
</STYLE>
</HEAD>



<div align="center"><div align="center" style="width: 661; height: 80">
<p style="text-align: center">News Flash</div>
<div align="center" style="width: 658; height: 80">
<p style="text-align: center">News Flash</div>
</div>
<p align="justify"><p align="justify"><p align="justify">
<%
Sub DrawPage()
%><center>
<div align="center">
<%
'Set the current record pointer to the first record of the recordset
rs.MoveFirst

'Loop through all the records in the recordset
while not rs.EOF

'Load recordset field values into local variables
Title = rs("News_title") & ""
Body = rs("News_body") & ""
DateTime = rs("News_Date") & ""
%>
<table width="790" border="0" height="48" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0"
cellspacing="0" align=center>
<tr>
<td width="104" height="21" bgcolor="#660066" style="font-size: 10pt; font-family: verdana; color: white"></td>
<td width="1625" height="21" bgcolor="#660066"><div><%=Title %></div></td>
<td height="21" bgcolor="#660066" width="162"><div><%=DateTime %></div></td>
</tr>

<tr>
<td width="104" height="12" bgcolor="#CC99FF" style="font-size: 10pt; font-family: verdana; color: black"></td>
<td width="1787" height="12" bgcolor="#CC99FF" style="font-size: 10pt; font-family: verdana; color: black" colspan="2">
<div style="width: 705; height: 13"><%=Body %></div></div></td>
</tr>

<tr>
<td width="1891" bgcolor="#CC99FF" style="font-size: 4pt; font-family: verdana; color: black" colspan="3" height="9"></td>
</tr>

<tr>
<td width="2011" height="6" colspan="3" style="font-size: 10pt; font-family: verdana; color: black">
<p align="center">
</td>
</tr>
</table>

<%
rs.MoveNext
wend
%>
<%
End Sub

'Database coding commence
dim rs, sql, cn, Title, Body, DateTime

'Set connection details
set cn = server.CreateObject("ADODB.Connection")
cn.Open "DSN=Trains;UID=sa;PWD=;DATABASE=Trains"

'Set sql string
sql = "SELECT * FROM News where News_Expiry >"
sql = sql & "'" & TRIM(Date()) & "'"
sql = sql & " order by news_id desc"

'Create a recordset
set rs = cn.Execute(sql)

if rs.EOF then
%>
<center>
<IMG SRC=images/tanda.gif>


<%
Response.Write "<b>There's no news to publish.</b>"
%>
</center>
<%
else
Call DrawPage()
End if
%>

</center>






<p align="center">
<p align="center">
<p align="center"><font face="Webdings" color="#CC99FF" size="7">
<marquee scrollamount="3">CDBFGHKSPITJQ</marquee></font>

</BODY>
</HTML>
Reply With Quote
  #2 (permalink)  
Old March 22nd, 2010, 06:03 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You *can* put it most any place.

But you can certainly put it directly into the open:
Code:
cn.Open "Provider=sqloledb;" & _ 
           "Server=YOURSERVERNAME;" & _
           "Database=Trains;" & _
           "User Id=sa;" & _
           "Password="
But provide a real user id and password, if available.
Reply With Quote
  #3 (permalink)  
Old March 22nd, 2010, 06:04 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;Some say Classic ASP won't work with DNS (ODBC).

no that no true. But why use ODBC when you dont have to. Here is IMO a better method to connect:

First get you connection string details out of each file. What if the server, UN, PW etc chnages and you have 50 pages? A real bugger making so many chnages!!!

Step 1 place this into a file (alter the variables) EG scripts/global.asp:

<%
dim conn,sql,EoF
const IUSER = "yourUserName"
const pWord = "yourPassword"
const DBNAME = "databaseName"
const DBSERVER = "machineName"

GetConnectionString = "Provider=SQLOLEDB.1; Password=" & pWord & "; Persist Security Info=True; User ID=" & IUSER & "; Initial Catalog=" & DBNAME & "; Data Source=" & DBSERVER & ";"

%>

Step 2:

Place this (I place at the top) in every file you would like to make a DB connection:

<!-- #include file ="scripts/Global.asp" -->
<% Set Conn = server.createobject("ADODB.Connection")
conn.open(GetConnectionString)
'now write your SQL
SQL = "SELECT ....."
'now execute it
set somevariable = conn.execute(sql)


NOTE - You should not use the SA account this is considered a bit of a security risk
__________________
Wind is your friend
Matt
Reply With Quote
  #4 (permalink)  
Old April 22nd, 2010, 12:47 PM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Default

It clearly says the login failed. It means either password is incorrect or "sa" doesn't have login permissions to the database. Also, you may want to test the connection using ODBC administrator on web Server with "sa" credentials.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String sumith ASP.NET 2.0 Basics 1 December 26th, 2008 08:30 PM
put part of html in string DOM Dj Kat Javascript How-To 3 February 22nd, 2006 04:28 AM
Connection String phungleon Classic ASP Basics 1 March 18th, 2005 05:51 AM
Connection String slgknjn VB Databases Basics 2 February 26th, 2005 03:14 AM
Connection String JsonTerre1 BOOK: ASP.NET Website Programming Problem-Design-Solution 5 November 1st, 2004 02:06 AM



All times are GMT -4. The time now is 09:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.