Hello friends

May i know how to connect a database to a web page??

Dani AI

Generated

Practical, step‑by‑step path for a Classic ASP login/register setup (builds on ’s suggestion to learn ADO and answers ’s “where to put code” question).

Start/structure: keep a small include file (for example dbconn.asp) that opens a database connection with appropriate credentials and closes it at the end of the request. Put the include at the very top of pages that need DB access using the server include directive so the connection object (for example conn) is available to the page. Keep SQL DDL and business logic separate from presentation where possible.

Example schema (SQL Server):

CREATE TABLE Users (
  Id INT IDENTITY(1,1) PRIMARY KEY,
  Username NVARCHAR(100) NOT NULL UNIQUE,
  PasswordSalt VARBINARY(32) NOT NULL,
  PasswordHash VARBINARY(64) NOT NULL,
  CreatedAt DATETIME NOT NULL DEFAULT GETDATE()
);

Safe insert/select pattern (assumes an open connection object named conn in dbconn.asp and a server-side hashing method or DB HASHBYTES usage):

' registration snippet (after include)
Dim usr, pwd
usr = Trim(Request.Form("username"))
pwd = Request.Form("password")

If Len(usr)=0 Or Len(pwd)<6 Then
  Response.Write "Invalid input"
  Response.End
End If

' generate salt and compute hash using a secure method (see notes)
' then use a parameterized command to store values
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO Users (Username, PasswordSalt, PasswordHash) VALUES (?, ?, ?)"
cmd.CommandType = 1
cmd.Parameters.Append cmd.CreateParameter("p1", 200, 1, 100, usr)
cmd.Parameters.Append cmd.CreateParameter("p2", 205, 1, Len(salt), salt)
cmd.Parameters.Append cmd.CreateParameter("p3", 205, 1, Len(hash), hash)
cmd.Execute
Set cmd = Nothing

Security & troubleshooting notes: always use parameterized commands to prevent SQL injection; never store plaintext passwords—use a strong salted hash (bcrypt/Argon2 preferred; if unavailable, use DB/hash functions on supported SQL Server versions and store salt+hash as binary). Serve pages over HTTPS. Test DB connectivity first with a DB client, check IIS Classic ASP is enabled, and confirm the DB user has only the necessary permissions. This gives a concise, secure workflow to connect forms to a database and implement basic register/login in Classic ASP.

Recommended Answers

All 3 Replies

Hi,
Use the following method.

set oConno = Server.CreateObject("ADODB.Connection")
set oRsMain = Server.CreateObject("ADODB.Recordset")
oConno.ConnectionString = "Provider=SQLOLEDB;Data Source=[servername];Initial Catalog=[database];User Id=[userid];Password=[password]"
oConno.Open

Hi,
Use the following method.

set oConno = Server.CreateObject("ADODB.Connection")
set oRsMain = Server.CreateObject("ADODB.Recordset")
oConno.ConnectionString = "Provider=SQLOLEDB;Data Source=[servername];Initial Catalog=[database];User Id=[userid];Password=[password]"
oConno.Open

HI vicky_rawat,

I am very much glad with ur answer for my question.


But i dont know where to write this code??How to write?and how to connect ??And i dont what to fill in the spaces i.e., Brackets.

Could u please send me the entire code with full details and one more thing is that i created a web page with login form and register form but i dont know how to connect to the database and how to retrieve data and insert all these things Could u please tell all those details..i visited so many sites i am not able to under stand could u please let me know.


regards
vinay

Hi vinay,

I am really sorry, but first you need to start learning ASP, as nobody here will do the spoonfeeding.

you need to first understand ADO.
Then the connection oject recordset object and then how to write connection string.

We can help you, if you get stuck somewhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.