How to access SQL Server in Active Server Page

Source: Internet
Author: User
Tags connection pooling odbc sql server driver odbc connection odbc sql server driver ole knowledge base strong password
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 ")%>
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.