| |
| |
Database Connection Strings (Access/SQL)
SummaryHow do I setup a database connection for MS Access (.MDB) or MS SQL database? ResolutionThere are two ways to do this: The first way does not require a use of a DSN (Data Source Name). This is the fastest and easiest method. Please choose either Microsoft Access | Microsoft SQL Server database. Microsoft Access (.mdb)
- DSNless Method for MS Access - (easiest)
Create a database connection in your .ASP code as follows:
<% Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "Microsoft.Jet.OLEDB.4.0;Data Source=c:\domains\myDomain.com\db\myDB.mdb;User Id=myLogin;Password=myPass;" Set rsmyTable = Conn.Execute("SELECT * From myTable") %>
Substitute myDomain.com, myDB, myLogin, myPass, myTable with your own specific details. This assumes your db is located in the \db directory although if you want you can place it in the wwwroot as well, however take care to update the path in the connectionstring to be c:\domains\myDomain.com\wwwroot\myDB.mdb. NOTE: Doing this will allow your database to be downloaded unless you use password protection (.htaccess).
- DSN Method for MS Access
- For MS Access (.mdb) files, copy the file to /db directory (one above wwwroot). NOTE: It must reside here for this to work.
- Open your control panel and click on ODBC Dsn icon.

- Click "Add New"
- Select "Microsoft Access", click Next
- Type in a DSN name, for example myDSN. The dropdown box should now contain the .MDB file.
- Click next and you are finished.
Create a database connection in your .ASP code as follows: <% Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open"DSN=myDsn;Uid=myUsername;Pwd=myPass;" Set rsmyTable = Conn.Execute("SELECT * From myTable") %>
Substitute myDomain.com, myDB, myLogin, myPass, myTable with your own specific details. Microsoft SQL
- DSNless Method for Microsoft SQL - (easiest)
Create a database connection in your .ASP code as follows:
<% Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "Driver={SQL Server};Server=sql.myDomain.com,1444;DATABASE=myDB;UID=myLogin;PWD=myPass;" Set rsmyTable = Conn.Execute("SELECT * From myTable") %>
Substitute myDomain.com, myDB, myLogin, myPass, myTable with your own specific details.
- DSN Method for Microsoft SQL
- Open your control panel and add a new SQL database (under Databases icon)
- Next ODBC Dsn icon.

- Click "Add New"
- Select "Microsoft SQL Server 2000", click Next
- Type in a DSN name, for example myDSN. The dropdown box should now contain the SQL database.
- Click next and you are finished.
Create a database connection in your .ASP code as follows:
<% Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open"DSN=myDsn;Uid=myUsername;Pwd=myPass;" Set rsmyTable = Conn.Execute("SELECT * From myTable") %>
Substitute myDomain.com, myDB, myLogin, myPass, myTable with your own specific details.
Additional InformationConnectionStrings.com
| Did this answer your question? |
Views: 824
Created by: Daniel Hendler
Date Created: 2004/08/12 02:00 AM
Last Updated: 2011/04/08 03:47 PM
Average Rating:     0% [0 Vote(s)]
|
|
|