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 virtual="/conn.asp" -->
<%
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.
<%@ 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
%>
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.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.