Connecting Classic ASP to SQL Server

Keep the SQL Server connection string in one server-side include so database pages share a single configuration. The example uses Windows integrated authentication, which avoids embedding a database password in the ASP source when IIS/SQL Server identities are configured appropriately. If SQL authentication is required, keep the secret in protected server configuration rather than client-visible code or downloads.

Include the connection settings

<!-- #include virtual="/conn.asp" -->

Current OLE DB provider

<%
Dim aConnectionString
aConnectionString = "Provider=MSOLEDBSQL19;" & _
  "Data Source=sql01.example.com;" & _
  "Initial Catalog=appdb;" & _
  "Integrated Security=SSPI;"
%>

Microsoft recommends the current MSOLEDBSQL driver generation for SQL Server. Driver 19 uses stronger encryption defaults, so production environments should be configured with a trusted server certificate and connection settings appropriate to the installed driver.

Open and close the ADO connection

<%@ Language="VBScript" %>
<% Option Explicit %>
<!-- #include virtual="/adovbs.inc" -->
<!-- #include virtual="/conn.asp" -->
<%
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = adModeRead
conn.ConnectionString = aConnectionString
conn.Open

' Run database work here.

conn.Close
Set conn = Nothing
%>

Connection errors

Microsoft OLE DB Driver for SQL Server
Connection attempt failed because the server, credentials, network path, encryption or certificate configuration could not be validated.

A connection failure is not proof that SQL Server is absent. Check the server/instance name, TCP/network access, credentials, database permissions, installed OLE DB driver, encryption settings and certificate trust.


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer