SQL Server
Applicable to
Profile
This article describes how to use ActiveX Data Objects (ADO) to establish a connection to SQL Server in an ASP script, while leveraging the connection pooling capabilities of ODBC 3.0.
More information
Connection pool
Enable ODBC connection pooling.
For additional information about connection pooling and instructions on how to enable the connection pooling feature, click the following article number to view the article in the Microsoft Knowledge Base:
164221 How to enable connection pooling in an ODBC application
ODBC DSN
Use the ODBC administrator to create a system data source name (DSN) on the computer where Microsoft Internet information Server (IIS) is installed. Specify the connection properties one at a time, and then reuse this property on each page. For example, in the Session_OnStart event for a Global.asa file, the connection property is defined as:
Session ("ConnectionString") = "dsn=sqlsysdsn;uid=<username>;" & _ "Pwd=<strong password>;D atabase= Pubs App=asp Script "
Ensure that all of the following conditions are true:
The Trusted connection box is not selected in the system DSN definition.
SQL Server security mode is not "Windows NT integration."
The UID is not empty in the connection properties.
Otherwise, the connection to SQL Server may fail, and you receive the following error message:
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.
Global.asa
Whether to use the Global.asa file is optional. In its place, a project typically created from this file can be placed on the first page of the application invocation. Assuming that the ASP script is in a folder that is not defined as a virtual directory in Internet Service Manager, but is located under another virtual directory, the Global.asa file containing the session variable and the DSN definition must remain in this virtual directory. Otherwise, you receive the following error message:
Microsoft OLE DB Provider for ODBC Drivers error ' 80004005 '
[Microsoft] [ODBC Driver Manager] Data source name not found and no
Default driver specified
Connections in ASP Scripts
Take advantage of connection pooling by opening and closing a connection to a database on each Active Server Page. To open this connection, type the following statement in the <Body> section of the page:
<% Set objdbconnection = Server.CreateObject ("ADODB. Connection ") OBJdbConnection.Open session (" ConnectionString ")%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.