Creating a Members Area in ASP

Preparation

For this example, we are going to use a MS SQL Server database. This doesn't mean you have to, as the SQL statements will work whatever the database; you'll just need to change the connection code.

Before we start writing any ASP code, create a new MS SQL Server database called testdb, and then create a new table in it called members. Add the following columns (we've included both the MS SQL Server, and the Access descriptions)

Name SQL Server Data Type

Access Data Type

Notes
id int (AutoIncrement=True) AutoNumber Primary Key
username varchar (20) Text (FieldSize=20) Unique
password varchar (20) Text (FieldSize=20)  

Now, we'll create a short ASP script that connects to the database. Save it as inc-dbconnection.asp.

inc-dbconnection.asp

<%
Dim objConn

'create an ADO connection object
Set objConn = Server.CreateObject("ADODB.Connection")

'open the connection to the database
'sqlservername = the name of the SQL server (if used)
'accessdb = the path to the access db from this script
'username = username to connect to the db
'password = password to connect to the db

'// Use this for SQL Server
objConn.Open "Driver={SQL Server};Server=sqlservername;" & _
    "UID=username;PASSWORD=password;DATABASE=testdb;"

'// Use this for an Access 2000 database
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("accessdb")

'// Use this for an Access database (earlier than 2000)
objConn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & Server.MapPath("accessdb")

'we are now connected to the database
%>

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor