ConnectionString Property

Microsoft Office Web Components Visual Basic

expression.ConnectionString

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

With the data source control, this property is equivalent to CurrentProject.BaseConnectionString in Microsoft Access. When the data source control creates a connection, the value of the data source control ConnectionString property may not be the same as the value returned by the ConnectionString property of the Connection object because the data source control uses other OLE DB providers to supply additional services. For example, on an HTML page containing a data source control with ID "MSODSC" the following expressions may not be equivalent.

Important   For information about secure data connections, see Making Connections to External Data Sources More Secure.

MSODSC.ConnectionString
MSODSC.Connection.ConnectionString
		

Example

This example establishes a connection to a database, queries the data, and then adds fields to PivotTable1 when the Web page containing the PivotTable1 is loaded.

Sub Window_OnLoad()

    Dim sConnStr
    Dim ptView
    
    ' Set a variable to the connection string.
    sConnStr = "Provider=sqloledb;Data Source=DataServer;Initial Catalog=Testing;Integrated Security=SSPI;"
    
    ' Set the connection string
    PivotTable1.ConnectionString = sConnStr

    ' Return all data from the Spending table.
    PivotTable1.CommandText = "Select * from Spending"
    
    Set ptView = PivotTable1.ActiveView
    
    ' The following four lines of code add fields to the row area and data
    ' areas of the PivotTable list.
    ptView.RowAxis.InsertFieldSet ptView.FieldSets("Project")
    ptView.RowAxis.InsertFieldSet ptView.FieldSets("Year")
    ptView.DataAxis.InsertFieldSet ptView.FieldSets("Budget")
    ptView.DataAxis.InsertFieldSet ptView.FieldSets("Actual")

End Sub