Add a database as a data source

With Microsoft Office SharePoint Designer 2007, you can connect to a variety of databases, including Microsoft SQL Server, Oracle, and other databases that are accessible by using the OLE DB (OLE DB: A component database architecture that implements efficient network and internet access to many types of data sources, including relational data, mail files, flat files, and spreadsheets.) protocol. By default, your Microsoft SharePoint site does not contain any database connections. To access a database, someone who has sufficient permissions must create the connection.

This article shows you how to connect to a database by using the Data Source Library. It also shows you how to create custom Structured Query Language (SQL) commands and how to modify the data source properties of an existing database connection in the Data Source Library.

In this article


Before you begin

There are a few things that you need to know before you can connect to a database. You need to know whether the site you are working on is a Windows SharePoint Services 3.0 site or a Microsoft Office SharePoint Server 2007 site, the name of the server where your database is located, the data provider that you use to access your database, and the kind of authentication that you want to use. If you are using a custom connection string to connect to your database, you also need to know that connection string.

What kind of database do I have?

With Office SharePoint Designer 2007, you can quickly connect to any database that resides on Microsoft SQL Server 2000 or Microsoft SQL Server 2005, or to any data source that uses the OLE DB protocol. If you know the connection string, you can also quickly connect to an Oracle database.

What data provider do I want to use?

With Office SharePoint Designer 2007, you can connect to a database by using any of three different data providers. These data providers are not mutually exclusive. For example, Microsoft SQL Server 2000 and Microsoft SQL Server 2005 are both OLE DB compliant and can be accessed by using the Microsoft .NET Framework Data Provider for OLE DB. However, the Microsoft .NET Framework Data Provider for SQL Server is specifically designed to work with Microsoft SQL Server 2000 and Microsoft SQL Server 2005 and may be the best choice if your database resides on either of these two server products.

Data providers are the software components that allow the client — in this case Office SharePoint Designer 2007 — to communicate with the database. Originally, each database management system was unique, and each had its own programming language for accessing and updating data. ODBC was one of the first attempts to standardize access to a variety of diverse database management systems. Data Views do not support ODBC providers. OLE DB was introduced after ODBC to provide more flexible access to databases. Many ODBC-compliant databases are also OLE DB compliant.

For more information about which data provider to use, see the following chart.

If you are connecting to a database that is ... Use ...
Microsoft SQL Server 2000 or Microsoft SQL Server 2005 Microsoft .NET Framework Data Provider for SQL Server
OLE DB-compatible Microsoft .NET Framework Data Provider for OLE DB
Oracle Microsoft .NET Framework Data Provider for Oracle
ODBC-compatible

Microsoft .NET Framework Data Provider for ODBC

Note Data Views do not support ODBC providers for database connections to any type of database, including MySQL. In the Configure Database Connection dialog box, you should disregard the option for using an ODBC provider.

What authentication method do I want to use?

Three separate authentication methods are available in the Configure Database Connection dialog box, including using a custom connection string.

Configure Database Connection dialog box

The authentication methods available in the Configure Database Connection dialog box

The authentication method that you want will be defined in part by the type of server that you are using and the data provider that you are using. For more information about which authentication method to use, see the following chart.

If your site is located on a server running ... And your data provider is ... See the section ...
Windows SharePoint Services 3.0 Microsoft .NET Framework Data Provider for SQL Server
— or —
Microsoft .NET Framework Data Provider for OLE DB
Connect to a database by saving the user name and password
Office SharePoint Server 2007 Microsoft .NET Framework Data Provider for SQL Server
— or —
Microsoft .NET Framework Data Provider for OLE DB
Connect to a database by using Single Sign-On authentication
Windows SharePoint Services 3.0
— or —
Office SharePoint Server 2007
Microsoft .NET Framework Data Provider for Oracle Connect to a database by using a custom connection string

Top of Page Top of Page

Connect to a database by saving the user name and password

When you use Connect to a database by saving the user name and password, Office SharePoint Designer 2007 generates a SQL-based connection string that stores the user name and password in the data source connection (a process known as SQL authentication). If your site is located on a server running Windows SharePoint Services 3.0, this is the preferred option for generating a connection string. You can also create a database connection by using a custom connection string. For more information, see the later section Connect to a database by using a custom connection string.

  1. If the Data Source Library task pane is not visible, on the Task Panes menu, click Data Source Library.
  2. In the Data Source Library task pane, under Database Connections, click Connect to a database.

 Note   If the Database Connections heading is collapsed, click the plus sign (+) to expand it.

  1. In the Data Source Properties dialog box, on the Source tab, click Configure Database Connection.
  2. In the Configure Database Connection dialog box, under Server Information, in the Server Name box, type the name of the server where your database resides.
  3. In the Provider Name box, do one of the following:
    • If you are connecting to an external Microsoft SQL Server 2000 database or an external Microsoft SQL Server 2005 database, click Microsoft .NET Framework Data Provider for SQL Server.
    • If you are connecting to an external database that is OLE DB compatible, click Microsoft .NET Framework Data Provider for OLE DB.
  4. Under Authentication, click Save this username and password in the data connection.
  5. In the User name box, type your user name.
  6. In the Password box, type your password.
  7. Click Next.

 Important   Because SQL authentication saves the user name and password as text in the data connection, any user with permission to open the site in Office SharePoint Designer 2007 can view these credentials. A security warning informs you that the user name and password are saved as text in the data connection and that other site members can access this data source. If you want other site members to access the database by using the same user name and password, click OK. If you do not want other site members to access the database by using the same user name and password, click Cancel. If your site is located on a server running Office SharePoint Server 2007, you can talk to your server administrator about configuring Single Sign-On, and then see the later section Connect to a database by using Single Sign-On authentication.

  1. In the Database list, click the database that you want to use as a data source, and then do one of the following:
    • Click Select a table or view, click the table or saved view that you want from the list, and then click Finish.
      By using this option, you create a default query that selects all records in the table or view. However, after you click Finish, you can modify the default query by clicking Fields, Filter, and Sort in the Data Source Properties dialog box. For more information, see the article Create a data source query.
    • Click Specify custom Select, Update, Insert, and Delete commands using SQL or stored procedures, and then click Finish.

 Note   This option is available only if your administrator has turned on the Enable Update Query Support option.

By using this option, you can create custom SQL commands. When you click Finish, the Edit Custom SQL Commands dialog box opens. In this dialog box, you can create commands and add parameters. After you create a custom SQL command, you can edit the query by clicking Edit Custom Query in the Data Source Properties dialog box. For more information, see Create custom SQL commands later in this article.

  1. In the Data Source Properties dialog box, click the General tab, type a name for the data source, and then click OK.

The new database connection now appears in the Data Source Library task pane.

 Note   If you are trying to connect to an external server running SQL Server, make sure that SQL Server authentication is enabled on that server.

Top of Page Top of Page

Connect to a database by using Single Sign-On authentication

If your site is located on a server running Office SharePoint Server 2007, this is the preferred option for generating a connection string. The Use Single Sign-On authentication option instructs the server to supply the user name and password for accessing the database. This option can be used when your site is part of a portal site that was created by using Office SharePoint Server 2007 and the administrator has enabled and configured Single Sign-On. With Single Sign-On, you can connect to an external database, even if it doesn't reside on the same server as your SharePoint site.

  1. If the Data Source Library task pane is not visible, on the Task Panes menu, click Data Source Library.
  2. In the Data Source Library task pane, under Database Connections, click Connect to a database.

 Note   If the Database Connections heading is collapsed, click the plus sign (+) to expand it.

  1. In the Data Source Properties dialog box, on the Source tab, click Configure Database Connection.
  2. In the Configure Database Connection dialog box, under Server information, in the Server Name box, type the name of the server where your database resides.
  3. In the Provider Name box, do one of the following:
    • If you are connecting to a database stored on a computer running Microsoft SQL Server, such as Microsoft SQL Server 2000 and Microsoft SQL Server 2005, click Microsoft .NET Framework Data Provider for SQL Server.
    • If you are connecting to a database that uses OLE DB, click Microsoft .NET Framework Data Provider for OLE DB.
  4. Under Authentication, click Use Single Sign-On authentication, and then click Settings.
  5. In the Single Sign-On Settings dialog box, do the following:
    • In the Application Name box, type the application name for your database.
    • In the Application field to use as the user name box, type the field in which your user name is stored.
    • In the Application field to use as the password box, type the field in which your password is stored.

 Note   If you do not have this information, ask your server administrator.

  1. Click Next.
  2. In the Database list, click the database that you want to use as a data source, and then do one of the following:
    • Click Select a table or view, click the table or saved view that you want from the list, and then click Finish.
      By using this option, you create a default query that selects all records in the table or view. However, after you click Finish, you can modify the default query by clicking Fields, Filter, and Sort in the Data Source Properties dialog box. For more information, see the article Create a data source query.
    • Click Specify custom Select, Update, Insert, and Delete commands using SQL or stored procedures, and then click Finish.

 Note   This option is available only if your administrator has turned on the Enable Update Query Support option.

By using this option, you can create custom SQL commands. When you click Finish, the Edit Custom SQL Commands dialog box opens. In this dialog box, you can create commands and add parameters. After you create a custom SQL command, you can edit the query by clicking Edit Custom Query in the Data Source Properties dialog box. For more information, see Create custom SQL commands later in this article.

  1. In the Data Source Properties dialog box, click the General tab, type a name for the data source, and then click OK.

The new database connection now appears in the Data Source Library.

 Note   If you cannot use SQL Server authentication on the server that is running SQL Server, make sure that Single Sign-On authentication is enabled for the server where your SharePoint site resides.

Top of Page Top of Page

Connect to a database by using a custom connection string

A connection string provides the information that an application or provider requires to communicate with a data source. A connection string usually supplies the location of the database server, the particular database to use, and the authentication information. With a custom connection string, you can specify the connection string that is used to connect to the database.

  1. If the Data Source Library task pane is not visible, on the Task Panes menu, click Data Source Library.
  2. In the Data Source Library task pane, click Connect to a database.

 Note   If the Database Connections heading is collapsed, click the plus sign (+) to expand it.

  1. In the Data Source Properties dialog box, on the Source tab, click Configure Database Connection.
  2. In the Configure Database Connection dialog box, select the Use Custom connection string check box, and then click Edit.
  3. In the Edit Connection String dialog box, in the Provider Name list, click the data provider that you want to use.
  4. In the Connection String text box, type your connection string.

An example of an OLE DB connection string:

Provider=myProvider;Data Source=myPath;Initial Catalog=catalogName;
User Id=username;Password=password;

An example of an Oracle connection string:

Data Source=myDatabase;User Id=username;
Password=password;Integrated Security=no;
  1. Click Next.
  2. In the Database list, click the database that you want to use as a data source, and then do one of the following:
    • Click Select a table or view, click the table or saved view that you want from the list, and then click Finish.
      By using this option, you create a default connection to the table or view. However, after you click Finish, you can specify a query by clicking Fields, Filter, and Sort in the Data Source Properties dialog box. For more information, see the article Create a data source query.
    • Click Specify custom Select, Update, Insert, and Delete commands using SQL or stored procedures, and then click Finish.

 Note   This option is available only if your administrator has turned on the Enable Update Query Support option.

By using this option, you can create or edit custom SQL commands. When you click Finish, the Edit Custom SQL Commands dialog box opens. In this dialog box, you can create commands and add parameters. After you create a custom SQL command, you can edit the query by clicking Edit Custom Query in the Data Source Properties dialog box. For more information, see Create custom SQL commands later in this article.

  1. In the Data Source Properties dialog box, click the General tab, type a name for the data source, and then click OK.

The new database connection now appears in the Data Source Library.

 Notes 

  • If you are trying to connect to an external server running SQL Server, make sure that SQL Server authentication is enabled on that server.
  • If you cannot use SQL Server authentication on the server that is running SQL Server, make sure that Single Sign-On authentication is enabled for the server where your SharePoint site resides.

Top of Page Top of Page

Create custom SQL commands

When you click the Specify custom Select, Update, Insert, and Delete commands using SQL or stored procedures option and then click Finish in the Configure Database Connection dialog box, the Edit Custom SQL Commands dialog box opens. In this dialog box, you can create custom SQL statements to retrieve or modify the data in a database.

There are four tabs in the Edit Custom SQL Commands dialog box, each corresponding to a common SQL command. They are:

  • Select    The SELECT command is used to retrieve data from a table.
  • Update    The UPDATE command is used to modify data in a table.
  • Insert    The INSERT INTO command is used to insert new rows into a table.
  • Delete    The DELETE command is used to delete rows from a table.

The Stored Procedure list displays all of the stored procedures that are available in the database that you are connecting to.

When the Edit Custom SQL Commands dialog box opens, any statement already applied to the data appears in the SQL Statement box. For example, if you create a database connection by clicking Select a table or view to select a table, and later you decide to edit the SELECT statement, you see the following statement in the SQL Statement box on the Select tab:

SELECT * FROM dbo.[your_table_name]

The asterisk in this statement is a wild-card character that means all. This SQL statement means select all of the fields for all of the records from this specific table. To edit the statement, click Edit Command to open the Command and Parameter Editor.

Command Parameter Editor dialog box

Edit the SQL query by typing directly in the SELECT command box.

Add SQL parameters

You can also create parameters for your SQL queries by clicking Add Parameter.

SQL parameters should be used anywhere that you might use a query string, meaning text enclosed in single quotation marks. Because using query strings in SQL statements creates a security vulnerability, SQL parameters are required in Office SharePoint Designer 2007 whenever you create an SQL statement that retrieves filtered data from a data source.

For example, Northwind Traders is a gourmet food distribution company. They store all of their business data in an SQL-based database. When they retrieve their entire product list from the products table, the resulting SQL query looks like this:

SELECT * FROM dbo.[Products]

This SQL statement retrieves all of the records in the product table. Northwind wants to retrieve a filtered list that includes only the items that are out of stock. The table includes a UnitsInStock field. Using traditional SQL, the statement that would retrieve this list looks like this:

SELECT * FROM dbo.[Products] WHERE UnitsInStock = '0'

The

'0'

in this statement is a query string. This query string should be replaced by a variable. For this example, you want to create a variable called OutOfStock. The new SQL statement looks like this:

SELECT * FROM dbo.[Products] WHERE UnitsInStock = @OutOfStock

To create the SQL statement by using the OutOfStock variable in this example, perform the following procedure:

  1. In the Command and Parameter Editor dialog box, in the SELECT command box, type the following string:
SELECT * FROM dbo.[Products] WHERE UnitsInStock = @OutOfStock
  1. Under Parameters, click Add Parameter.
  2. The variable that you want to define is OutOfStock, so in the Name column, type OutOfStock.
  3. In the Parameter Source list, click None.
  4. Because the value that you want to match is 0, in the DefaultValue box, type 0.

Command and Paramater Editor with SQL parameter statement

  1. Click OK.

You can now see the new SQL statement in the Edit Custom SQL Commands dialog box.

Edit Custom SQL Commands dialog box with SQL statement

  1. Click OK again.

In the Data Source Properties dialog box, the Edit Custom Query button appears on the Source tab.

Data Source Properties dialog box with the Edit Custom Query button

Top of Page Top of Page

Modify the data source properties of an existing database connection

After you configure a database connection, you can later modify the connection at any time. For example, you might want to create a new query, modify an existing one, or create a custom SQL statement.

  1. On the Task Panes menu, click Data Source Library.
  2. In the Data Source Library, click the database connection that you want to modify, and then click Properties.

If the database connection uses a custom SQL query, the Data Source Properties dialog box looks like the one in the following illustration.

Data Source Properties dialog box with the Edit Custom Query button

If the database connection does not use a custom SQL query, the Data Source Properties dialog box looks like the one in the following illustration.

Data Source Properties dialog box with the Query section

  1. In the Data Source Properties dialog box, do any of the following:
    • If there is a Query area with buttons, click those buttons to add or remove fields or to create or modify a filter or sort order.
    • If there is a Query area with buttons, click Configure Database Connection to apply a custom SQL query to the connection. After you click Configure Database Connection, click Next.

 Important   Because SQL authentication saves the user name and password as text in the data connection, any user with permission to open the site in Office SharePoint Designer 2007 can view these credentials. A security warning informs you that the user name and password are saved as text in the data connection and that other site members can access this data source. If you want other site members to access the database by using the same user name and password, click OK. If you do not want other site members to access the database by using the same user name and password, click Cancel. If your site is located on a server running Office SharePoint Server 2007, you can talk to your server administrator about configuring Single Sign-On, and then see the later section Connect to a database by using Single Sign-On authentication.

In the Configure Database Connection dialog box, click Specify custom Select, Update, Insert, and Delete commands using SQL or stored procedures, and then click Finish.

The Edit Custom SQL Commands dialog box opens. In this dialog box, you can create your custom SQL statement. For more information, see Create custom SQL commands earlier in this article.

  • If there is an Edit Custom Query button, click it to open the Edit Custom SQL Commands dialog box, where you can add, modify, or delete custom SQL statements.

Top of Page Top of Page

 
 
Applies to:
SharePoint Designer 2007