INF: How to Access SQL Server Within Active Server PagesID: Q169377
|
This article describes how to establish connections to SQL Server within an ASP script using ActiveX Data Objects (ADO), while taking advantage of the connection pooling feature of ODBC 3.0.
Q164221 : How to Enable Connection Pooling in an ODBC Application
Session("ConnectionString") =
"dsn=SQLSysDSN;uid=sa;pwd=;DATABASE=pubs;APP=ASP Script"
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed- User: _
Reason: Not defined as a valid user of a trusted SQL Server connection.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
<%
Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open Session("ConnectionString")
%>
<%
OBJdbConnection.Close
Set OBJdbConnection = Nothing
%>
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][DBNMPNTW]Connection broken.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver]Communication link failure
Global.asa
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
Session("ConnectionString") =
"DSN=SQLSysDSN;UID=sa;PWD=;DATABASE=pubs;APP=ASP script"
Session("ConnectionTimeout") = 15
Session("CommandTimeout") = 30
End Sub
Sub Session_OnEnd
End Sub
</SCRIPT>
Authors.asp
<HTML>
<HEAD>
<TITLE>All Authors</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<% Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.ConnectionTimeout = Session("ConnectionTimeout")
OBJdbConnection.CommandTimeout = Session("CommandTimeout")
OBJdbConnection.Open Session("ConnectionString")
Set SQLStmt = Server.CreateObject("ADODB.Command")
Set RS = Server.CreateObject ("ADODB.Recordset")
%>
<p>
<table border="0" bordercolor="#000000">
<%
SQLStmt.CommandText = "select * from authors"
SQLStmt.CommandType = 1
Set SQLStmt.ActiveConnection = OBJdbConnection
RS.Open SQLStmt
Do While Not RS.EOF
%>
<TR>
<TD Width = 150 ALIGN=LEFT>
<FONT SIZE=+1>
<%= RS("au_id") %>
</FONT></TD>
<TD></TD>
<TD Width = 150 ALIGN=LEFT>
<FONT SIZE=+1>
<%= RS("au_lname") %>
</FONT></TD>
<TD Width = 150 ALIGN=LEFT>
<FONT SIZE=+1>
<%= RS("au_fname") %>
</FONT></TD>
<TD Width = 150 ALIGN=LEFT>
<FONT SIZE=+1>
<%= RS("phone") %>
</FONT></TD>
</TR>
<%
RS.MoveNext
Loop
%>
</table>
<hr>
<p>
</BODY>
<% OBJdbConnection.Close
Set OBJdbConnection = Nothing
%>
</HTML>
Additional query words: browser explorer web sqlfaqtop
Keywords : kbenv kbinterop kbtshoot SSrvProg
Version : 4.2x 6.0 6.5, 3.0 4.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 10, 1999