Thursday, March 8, 2007

How do I Connect with My MS SQL2K Database using ASP ?

To connect with your MS SQL2K Database via Web using an ASP programming language, use the following connection string format;

'to define the variables
Dim conn, rs, sql

'to create a connection object
Set Conn=Server.CreateObject("ADODB.Connection")

'to create a database connection
Conn.open "Driver={SQL Server}
;Server=ContactUsForTheServerIPToUse
;Database=YourDatabaseName
;Uid=YourUserID
;Pwd=YourPassword
;"

'to access a table within a database
sql="select * from yourTable"
rs.Open sql,Conn,adOpenDynamic,adLockBatchOptimistic

'insert your process codes here

'to close a database connection
conn.close
set conn = nothing
rs.close
set rs = nothing

NOTE
The above sample connection string assumes that the "RUNNING PROGRAM FILE" is located inside your Virtual FTP Server's /www root sub-directory.

No comments: