Connecting to a Microsoft SQL Server Database Using ASP/ADO
This example describes using ASP/ADO to connect to a Microsoft SQL Server Database.
Replace the db_
fields with the information for your database from the Hosting Control Panel. For more information, see Locating Your MS SQL Database Connection Strings for more information.
'Sample Database Connection Syntax for ASP and SQL Server.
Dim oConn, oRs
Dim qry, connectstr
Dim db_name, db_username, db_userpassword
Dim db_server
db_server = "whsql01.mesa1.secureserver.net"
db_name = "your_dbname"
db_username = "your_dbusername"
db_userpassword = "your_dbpassword"
fieldname = "your_field"
tablename = "your_table"
connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename
Set oRS = oConn.Execute(qry)
Do until oRs.EOF
Response.Write ucase(fieldname) & ": " & oRs.Fields(fieldname)
oRS.MoveNext
Loop
oRs.Close
Set oRs = nothing
Set oConn = nothing
%>