AdoQueryConnection.Connection 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用于 对象的AdoQueryConnection连接字符串。
public:
abstract property System::String ^ Connection { System::String ^ get(); void set(System::String ^ value); };
public abstract string Connection { get; set; }
member this.Connection : string with get, set
Public MustOverride Property Connection As String
属性值
对象表示AdoQueryConnection的数据连接的连接字符串。
示例
在下面的示例中,Button 控件的事件处理程序使用 ADOQueryConnection 类的 Connection 属性更新名为 Employees 的辅助数据源的连接字符串,以便通过在主数据源的 ServerName 域中输入的值指向新服务器。 然后, Execute() 使用 类的 DataConnection 方法在新服务器上重新查询数据连接。
public void ChangeServerName_Clicked(object sender, ClickedEventArgs e)
{
// Get the Employees connection from the
//DataConnections collection.
AdoQueryConnection myAdoQueryConnection =
(AdoQueryConnection)(this.DataConnections["Employees"]);
// Get the new server name from the ServerName field in
// the main data source.
XPathNavigator myNav =
CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName",
NamespaceManager);
string newServer = myNav.InnerXml;
// Build the new connection string.
string connectionString =
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;";
connectionString += "Initial Catalog=SalesDB;Data Source=" +
newServer;
// Set the new connection string.
myAdoQueryConnection.Connection = connectionString;
// Requery the data source.
myAdoQueryConnection.Execute();
}
Public Sub ChangeServerName_Clicked(ByVal sender As Object, _
ByVal e As ClickedEventArgs)
' Get the Employees connection from
' the DataConnections collection.
Dim myAdoQueryConnection As AdoQueryConnection = _
DirectCast(Me.DataConnections("Employees"), AdoQueryConnection)
' Get the new server name from the ServerName field in
' the main data source.
Dim myNav As XPathNavigator = _
CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName", _
NamespaceManager)
Dim newServer As String = myNav.InnerXml
' Build the new connection string.
Dim connectionString As String = _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;"
connectionString = connectionString & _
"Initial Catalog=SalesDB;Data Source=" & newServer
' Requery the data source.
myAdoQueryConnection.Execute()
End Sub
注解
ADOQueryConnection 类的 Connection 属性提供对连接字符串的访问,ADO 数据连接使用该连接字符串来连接到 ActiveX 数据对象/OLEDB 外部数据源。
注意:ADOQueryConnection 类限制为仅适用于 Microsoft SQL Server 和 Microsoft Access 数据库。
此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。
可以通过 Microsoft InfoPath Filler 或 Web 浏览器内打开的表单中运行的代码访问此类型或成员。