Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > DNS-less Connections

Reply
Thread Tools

DNS-less Connections

 
 
slc@cfl.rr.com
Guest
Posts: n/a
 
      02-19-2005
Help,

I'm trying to make the following asp code work using a DNS-Less
connection on a windows 2000 server running IIS and ODBC 4.0 driver.
The Access database (odbc_exmp.mdb) was made using Access 2002. The
code works if I set up a DNS on the server under the ODBC drivers.
What I'm I doing wrong and what do I change the code to, to make it
work using DNS-Less connection?

Thanks for any help
Kevin.


<% Response.buffer = true %>
<html>
<head>
<title>Testing of odbc_exmp asp</title>
</head>
<body>
<%
'Next 4 lines do not work
Dim rs, dbPath
dbPath = "c:\safety\tr\odbc_exmp.mdb"
Set rs = Server.CreateObject("ADODB.Connection")
rs.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath

' The next 3 lines work with DNS set up on the windows 2000
server-IIS-ODBC 4.0 drivers
'Dim rs
'Set rs = Server.CreateObject ("ADODB.Recordset")
'rs.Open "names", "DSN=odbc_exmp",,, &H0200

While Not rs.EOF
'Response.Write "ID : " & rs("id") & "<br>"
Response.Write "First Name : " & rs("first_name") & "<br>"
Response.Write "Last Name : " & rs("last_name") & "<br>"
Response.Write "<br>"
Response.Write "<br>"
rs.MoveNext
Wend

rs.Close
Set rs = Nothing %>
</body>
</html>

 
Reply With Quote
 
 
 
 
Veign
Guest
Posts: n/a
 
      02-19-2005
> Dim rs, dbPath
> dbPath = "c:\safety\tr\odbc_exmp.mdb"
> Set rs = Server.CreateObject("ADODB.Connection")


You have the variable named RS but have instantiated a Connection object.
Try changing it to an ADODB.Recordset

> rs.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath


You need some sort of SQL statement of something to let it know what to pull
from the database.

'---------------------------------------Code Sample:
'Create the Connection string
Dim strConnStr, dbPath
dbPath = "c:\safety\tr\odbc_exmp.mdb"
strConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath

'Create the SQL Statement
Dim strSQL
strSQL = "SELECT id, first_name, last_name FROM MyTable

'Open the Recordset
Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open strSQL, strConnStr

'Loop through the records
With RS
If Not .EOF Then
Do Until .EOF
Response.Write "ID : " & RS("id").Value & "<br />"
.MoveNext
Loop
End If
End With

'Cleanup
RS.Close
Set RS = Nothing
'-------------------------End Code sample


**- Make sure you change MyTable to the actual table name in your DB
** - On the line 'RS.Open strSQL, strConnStr' you should include the
constants for a Forward Only, Read only recordset (firehose recordset) as
this is the most efficient kind in this type of use

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Help,
>
> I'm trying to make the following asp code work using a DNS-Less
> connection on a windows 2000 server running IIS and ODBC 4.0 driver.
> The Access database (odbc_exmp.mdb) was made using Access 2002. The
> code works if I set up a DNS on the server under the ODBC drivers.
> What I'm I doing wrong and what do I change the code to, to make it
> work using DNS-Less connection?
>
> Thanks for any help
> Kevin.
>
>
> <% Response.buffer = true %>
> <html>
> <head>
> <title>Testing of odbc_exmp asp</title>
> </head>
> <body>
> <%
> 'Next 4 lines do not work
> Dim rs, dbPath
> dbPath = "c:\safety\tr\odbc_exmp.mdb"
> Set rs = Server.CreateObject("ADODB.Connection")
> rs.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
>
> ' The next 3 lines work with DNS set up on the windows 2000
> server-IIS-ODBC 4.0 drivers
> 'Dim rs
> 'Set rs = Server.CreateObject ("ADODB.Recordset")
> 'rs.Open "names", "DSN=odbc_exmp",,, &H0200
>
> While Not rs.EOF
> 'Response.Write "ID : " & rs("id") & "<br>"
> Response.Write "First Name : " & rs("first_name") & "<br>"
> Response.Write "Last Name : " & rs("last_name") & "<br>"
> Response.Write "<br>"
> Response.Write "<br>"
> rs.MoveNext
> Wend
>
> rs.Close
> Set rs = Nothing %>
> </body>
> </html>
>



 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-19-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Help,
>
> I'm trying to make the following asp code work using a DNS-Less
> connection on a windows 2000 server running IIS and ODBC 4.0 driver.
> The Access database (odbc_exmp.mdb) was made using Access 2002. The
> code works if I set up a DNS on the server under the ODBC drivers.
> What I'm I doing wrong and what do I change the code to, to make it
> work using DNS-Less connection?
>
> Thanks for any help
> Kevin.
>
>
> <% Response.buffer = true %>
> <html>
> <head>
> <title>Testing of odbc_exmp asp</title>
> </head>
> <body>
> <%
> 'Next 4 lines do not work


What does "doesn't work" mean? Error messages? Incorrect behavior? Please
try to describe your symptoms without using the words "doesn't work", or "no
luck", or some other phrase that assumes your readers are able to read your
mind.

> Dim rs, dbPath
> dbPath = "c:\safety\tr\odbc_exmp.mdb"
> Set rs = Server.CreateObject("ADODB.Connection")
> rs.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath


"rs" for a connection object??? Do you want it make it impossible for
someone to debug your code?? Join the rest of the world and use "cn" or
"conn" for the name of your connection object variable.
>
> ' The next 3 lines work with DNS set up on the windows 2000
> server-IIS-ODBC 4.0 drivers
> 'Dim rs
> 'Set rs = Server.CreateObject ("ADODB.Recordset")
> 'rs.Open "names", "DSN=odbc_exmp",,, &H0200


You've just redefined the rs variable. It's now a recordset object. Was that
intentional? Anyways, it's a bad idea to use a connection string in your
recordset's Open statement. You may be disabling connection pooling by doing
so. Always use an explicit connection object.

It's also not a good idea to open your entire names table when your intent
is to display two of the fields in it. Do this instead:

Dim rs, dbPath, cn, sSQL
dbPath = "c:\safety\tr\odbc_exmp.mdb"
sSQL= "Select [id],first_name,last_name From [names]"
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
Set rs = cn.Execute(sSQL,,1)


For a potentially major performance improvement, use a GetRows array:

dim arData
If Not rs.EOF then arData = rs.GetRows
rs.close: set rs=nothing
cn.close: set cn=nothing
if isArray(arData) then
dim i
for i = 0 to ubound(arData,2)
Response.Write "ID : " & arData(0,i) & "<br>"
Response.Write "First Name : " & arData(1,i) & "<br>"
Response.Write "Last Name : " & arData(2,i) & "<br>"
Response.Write "<br>"
Response.Write "<br>"
next
else
response.write "No Records were returned"
end if


HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
brownk10@gmail.com
Guest
Posts: n/a
 
      02-20-2005
Chris,

Thank You for the sample code.
I fix the line that says strSQL = "SELECT id, first_name, last_name
FROM MyTable
to read
strSQL = "SELECT id, first_name, last_name FROM [MyTable]"
and it works grate.

(Boy, was my code mested up)

Again Thanks for the Help.

Kevin

 
Reply With Quote
 
slc@cfl.rr.com
Guest
Posts: n/a
 
      02-20-2005
Bob,

Thanks for the Help, your code works grate.
I will try to do beater need time on describing my symptoms.
Again Thanks for the help and setting me strate.

Kevin

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lingering Idle Oracle Connections? Persistent connections? jobs ASP .Net 2 11-16-2007 03:37 AM
Madlax Volume One: Connections Anime DVD Review @ Ascully.co Silverstrand Front Page News 0 07-02-2005 11:33 PM
New access on the block point dumps wireless connections Jerry Paquette Wireless Networking 6 09-15-2004 06:32 PM
Restore network connections unreliable Monte Grant Wireless Networking 1 08-17-2004 08:33 PM
Network connections not automatically restored at startup =?Utf-8?B?cmp3?= Wireless Networking 0 07-31-2004 08:05 PM



Advertisments