Beruflich Dokumente
Kultur Dokumente
com/ado/ado_conn
ect.asp
ADO Database Connection
« Previous Next Chapter »
Before a database can be accessed from a web page, a database connection has to be
established.
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>
Note, from the example above, that you have to specify the Microsoft Access database
driver (Provider) and the physical path to the database on your computer.
If you have an ODBC database called "northwind" you can connect to the database with
the following ASP code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "northwind"
%>
With an ODBC connection, you can connect to any database, on any computer in your
network, as long as an ODBC connection is available.
An ODBC Connection to an MS Access Database
Note that this configuration has to be done on the computer where your web site is
located. If you are running Personal Web Server (PWS) or Internet Information Server
(IIS) on your own computer, the instructions above will work, but if your web site is
located on a remote server, you have to have physical access to that server, or ask your
web host to do this for you.
http://msdn.microsoft.com/en-us/library/cf131f6b%28VS.80%29.aspx
You can establish communication between your application and an Access database by
creating a connection that points to the actual database file (.mdb).
You connect to data in Access files by running the Data Source Configuration Wizard
and selecting Database on the Choose a Data Source Type page.
Tip
Drag an .mdf or .mdb file from Windows Explorer into Solution Explorer to automatically
configure your connection and start the Data Source Configuration Wizard ready for
you to select the objects to use in your application.
You can start the wizard by selecting the Add New Data Source command from the
Data menu or from within the Data Sources window. Alternatively, you can select the
Add Existing Item command from the Project menu and browse to the desired database
file.
After completing the wizard, a copy of the database (.mdb file) and a strongly typed
dataset file (.xsd) are added to your project. The selected database objects are
immediately available in the Data Sources Window for dragging onto your form. For
more information, see Displaying Data Overview.
Note
When adding the .mdb file through the Data Source Configuration Wizard, you are
given the choice of adding the file to your project or leaving it in its original location. For
more information, see How to: Manage Local Data Files in Your Project.
Note
The dialog boxes and menu commands you see might differ from those described in Help
depending on your active settings or edition. To change your settings, choose Import and
Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To connect to data in an Access database with the Add New Data Source
command
1. Select Add Existing Item from the Project menu, or drag the .mdb file from
Windows onto Solution Explorer.
2. Expand the tree of objects, and select the database objects to use in your
application.
3. Replace the default DataSet name if desired.
4. Click Finish.
The dataset you just created is now available in the Data Sources window. Open
the Data Sources window by selecting Show Data Sources from the Data menu.
Next Steps
To add functionality to your application
• Select items in the Data Sources window and drag them onto a form. For more
information, see Displaying Data Overview.
Note
If the data source does not appear in the Data Sources window, click the Refresh button
in the window.
Security
Storing sensitive information (such as the server name, user name, and password) can
affect the security of your application. Using Windows Authentication (also known as
integrated security) is a more secure way to control access to a database. For more
information, see Securing Connection Strings.
See Also
Tasks
Concepts