[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
ASPFAQ_Connect_to_SQLServer_OLEDB

How to connect to an MS SQL Server database using OLEDB?

OLEDB, the successor of ODBC, provides standard data access.

ADODB is based on Microsoft's ADO (ActiveX Data Objects) data-access method used to connect, navigate and manipulate different databases.

Place this script in the top of your ASP page where you access the database from.

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=SQLOLEDB;Data Source=lillu;Initial Catalog=entries;UserId=sa;Password=;" 
Conn.Open
%>


Or better, if you save this script an asp file eg. connection.asp, then you can reference it from any ASP page. Make sure the ConnectionString appears on a single line.

Set the relevant userid and password properties in the ConnectionString. If there are no such settings, leave them as is.

Placed this script in the top of every ASP file that you want to have a database connection.

<% @Language=VBScript%>
<% Option Explicit %>
<!--#include file="adovbs.inc"-->
<!--#include file="connection.asp"-->


The adovbs.inc is a file that comes with IIS. This file has all of the ADO constants defined which are needed when connecting to databases.

Related threads:
connecting to a sql server database

Back to ASP FAQ

last edited (April 29, 2004) by lillu, Number of views: 2043, Current Rev: 4 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.