Gå videre til hovedindhold
Ring til os
Telefonnumre og åbningstider
Hjælpecenter

Udforsk vores ressourcer for onlinehjælp

Hjælp

Windows Hosting (Plesk) Hjælp

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

Replace the db_ fields with the information for your database. For more information, see Find your connection strings in Web & Classic Hosting 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
%>

Community-relateret

bennyboy's Avatar
Setting up ASP Schema for MSSQL Database in Plesk

2 Besvarelser

Last posted about 3 years ago.

pjdev's Avatar
No button to add sql server web to VPS

2 Besvarelser

Last posted almost 2 years ago.

AsimPk's Avatar
Not Showing MS Sql Server on CPanel

3 Besvarelser

Last posted almost 2 years ago.

Kan du ikke finde det du leder efter? Søg i Community