Lesson 2: Creating a Connection to the Sample Database
The first step is to create a connection to the AdventureWorks sample database in order to generate a list of fields for the report definition.
Note
If you are using SQL Server Express with Advanced Services, the connection data source must include the SQL Server Express named instance. By default, the connection string for the AdventureWorks sample database is "Data Source=localhost\SQLExpress; Initial Catalog=AdventureWorks". For more information, see Reporting Services in SQL Server Express with Advanced Services
To create a connection to AdventureWorks
- Replace the code for the OpenConnection() method in your project with the following code:
Public Sub OpenConnection()
' Create a connection object
m_connection = New SqlConnection()
' Create the connection string
m_connectString = "data source=localhost;initial catalog=AdventureWorks;integrated security=SSPI"
m_connection.ConnectionString = m_connectString
' Open the connection
m_connection.Open()
End Sub 'OpenConnection
public void OpenConnection()
{
// Create a connection object
m_connection = new SqlConnection();
// Create the connection string
m_connectString = @"data source=localhost;initial catalog=AdventureWorks;integrated security=SSPI";
m_connection.ConnectionString = m_connectString;
// Open the connection
m_connection.Open();
}
Note
You should replace the connection string used here with a connection string that is valid for your particular configuration. The previous connection string assumes that you have installed the AdventureWorks database to a local instance of SQL Server.