Home Guides Glossary

Connecting to a Microsoft SQL Server Database Using ASP/ADO

This example describes using ASP/ADO to connect to a Microsoft SQL Server Database.

You must have your web.config file set to use full trust. For more information, see What trust level can I use when running ASP.NET?

Replace the db_ fields with the information for your database from the Hosting Control Panel. For more information, see Find your connection strings for more information.

<%@ Page aspcompat=true %>
<%

'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 = "server name"
db_name = "db username"
db_username = "db username"
db_userpassword = "db password"
dim fieldname = "your_field"
dim tablename = "your_table"

connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
oConn = Server.CreateObject("ADODB.Connection")
oConn.Open(connectstr)

qry = "SELECT * FROM " & tablename

oRS = oConn.Execute(qry)

Do until oRs.EOF
Response.Write(ucase(fieldname) & ": " & oRs.Fields(fieldname))
oRS.MoveNext
Loop
oRs.Close


oRs = nothing
oConn = nothing
%>

Domain Registration

Pay less for website domain names. Register your own .com, .net or .org for as low as $10.18 per year. We have everything you need to get online with your new domain.

Website Builder

Build an amazing website in just under an hour with Website Builder. Take advantage of designs created just for your industry and then customize them to reflect your one-of-a-kind idea.

Website Security

Protect your website and keep customers safe. Your comprehensive Website Security solution. Get peace of mind by securing your websites.

cPanel Hosting

Everything needed to give your website the high-performance home it deserves.  Protect transactions and secure your customer's data with a SSL Certificate
Copyright © 2005 - 2024.  All rights reserved.  Privacy Policy