Basic Databases Part 1
page 2 of 4
by . .
Feedback
Average Rating: 
Views (Total / Last 10 Days): 25648/ 37

Step 1 : Connecting

Step 1: Connecting

For beginners, this is the hardest phase, but I'm assuming that you can work around and use intelligence to find out what the statements are (this is not a copy and paste operation!). Well I'll give you the code and then I'll explain it.

DSN-LESS

Dim objConn             'Declare Variables
Dim connStr
Set objConn = Server.CreateObject("ADODB.Connection")       'Set objConn as an Object
connStr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=F:\My Documents\aspaStuff\nwind.mdb; "
objConn.Open(connStr)
        'Use the object's method passing it a variable

Where to begin? After the declaring of variables we move onto the Set objConn line. The Set keyword is different from doing x = 1, set tells it to be more than a variable (usually an object). The Server.CreateObject tells the server to create an object and call it objConn, ADODB.Connection is an ADO (ActiveX Data Object) Connection, this sets up your connection to the database. Next comes the connStr. This line tells the ADO object what database driver it is using and where this database is. I'm using the northwind database stored on a directory on my hard drive, the IIS version is a little different (See: PWS and IIS ). The final line uses one of the object's methods to open the connection using the variable connStr (to tell it where to look and what to use).

DSN

Dim objConn
Dim connStr

Set objConn = Server.CreateObject("ADODB.Connection")
connStr = "DSN=nWind"
objConn.Open(connStr)

You're probably saying - "Hey! This is way easier than DSN-Less!" But if you've read the DSN tutorial, then you'll know better. DSN's can be much better but only if you are sitting at the server and are able to do it yourself and make sure its done right, as there are alot of things that can go wrong, I know, I had a run-in with a guy, where I showed him exactly what to do and he messed it up. But DSN does have better security with passwords if you're going to use one that has sensitive data and works better with SQL Server (Well that's any database server (Access is NOT a database server)).


View Entire Article

User Comments

Title: SQL SERVER 2000   
Name: Anchal
Date: 2005-03-17 12:49:41 PM
Comment:
This is a great help for me...as I am just starting up with ASP and DATABASE and ADO

one thing...example you took is based on MS ACCESS...
Would it be similar for the MS SQL SERVER 2000???

Please Advice...it would be a great help..

Anchal
Title: Connection error   
Name: lumy
Date: 2005-03-01 8:59:52 AM
Comment:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.
/currency/respond.asp, line 33

Please assist.
Title: Great Help   
Name: Rizwan
Date: 2005-01-15 4:16:22 AM
Comment:
This is really great help for newbies, also for those who forget forget the logical procedure of database programing.
Thanks you Mr. Author!

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 4:19:17 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search