共用方式為


SqlCeRemoteDataAccess.Pull Method (String, String, String)

從遠端 SQL Server 資料庫下載資料,並且將資料儲存在本機 SQL Server Compact 3.5 資料庫的單一資料表中。

命名空間: System.Data.SqlServerCe
組件: System.Data.SqlServerCe (在 system.data.sqlserverce.dll)

語法

'宣告
Public Sub Pull ( _
    localTableName As String, _
    sqlSelectString As String, _
    oleDBConnectionString As String _
)
public void Pull (
    string localTableName,
    string sqlSelectString,
    string oleDBConnectionString
)
public:
void Pull (
    String^ localTableName, 
    String^ sqlSelectString, 
    String^ oleDBConnectionString
)
public void Pull (
    String localTableName, 
    String sqlSelectString, 
    String oleDBConnectionString
)
public function Pull (
    localTableName : String, 
    sqlSelectString : String, 
    oleDBConnectionString : String
)

參數

  • localTableName
    SQL Server Compact 3.5 資料表的名稱,此資料表將接收擷取的 SQL Server 記錄。如果資料表已經存在,便會發生錯誤。
  • sqlSelectString
    任何有效的 Transact-SQL 陳述式 (包括 SELECT 陳述式和預存程序),這種陳述式會指定要從 SQL Server 資料庫中擷取哪些資料表、資料行和資料錄,以便儲存於 SQL Server Compact 3.5 資料庫中。
  • oleDBConnectionString

備註

如果包含 SQL Server Compact 3.5 伺服器代理程式的虛擬目錄設定為使用基本驗證或整合式 Windows 驗證,則必須指定 InternetLoginInternetPassword 屬性。sqlSelectString 可以控制從 SQL Server 資料表所提取的資料。如果產生的資料錄集含有不支援的資料類型 (例如 Timestamp),就會發生錯誤。sqlSelectString 可以指定 WHERE 子句控制所要傳回的記錄。例如,SELECT * FROM Customers WHERE State='CA' 會只擷取居住於加州 (California) 的客戶。此外,sqlSelectString 還支援資料列傳回的預存程序或檢視。

如果使用 SQL Server 驗證,則 OLEDBConnectionString 中指定的使用者識別碼必須具有讀取 SQL Server 資料表的權限。

如果在 OLEDBConnectionString 中設定 INTEGRATED SECURITY="SSPI" 來使用 Windows 驗證,則網際網路使用者必須具有讀取 SQL Server 資料表的權限。下列各項作業將根據驗證方法識別網際網路使用者:

  • 當 Microsoft Internet Information Services (IIS) 虛擬目錄設定為使用匿名存取時,網際網路使用者會在「網際網路來賓帳戶」(IUSR_computername) 的識別之下執行。如果您將另一個 Windows 使用者帳戶設定為「網際網路來賓帳戶」,則網際網路使用者會在該帳戶的識別之下執行。

  • 當 IIS 虛擬目錄設定為使用基本驗證時,網際網路使用者會在 Windows 使用者帳戶 (用戶端已提供網際網路使用者和密碼) 的識別之下執行。

  • 當 IIS 虛擬目錄設定為使用整合式 Windows 驗證時,網際網路使用者會在 Windows 使用者帳戶 (用戶端已提供網際網路使用者和密碼) 的識別之下執行。

如需有關資料存取及限制的詳細資訊,請參閱《SQL Server Compact 3.5 線上叢書》內的<支援的資料類型與資料類型對應>和<RDA 限制>。

範例

下列範例會建立 SqlCeRemoteDataAccess 物件、設定數個屬性,然後呼叫 Pull 方法。

' Connection String to the SQL Server
'
Dim rdaOleDbConnectString As String = "Data Source=MySqlServer;Initial Catalog=AdventureWorks; " & _
    "User Id=username;Password = <password>"

' Initialize RDA Object
'
Dim rda As SqlCeRemoteDataAccess = Nothing

Try
    ' Try the Pull Operation
    '
    rda = New SqlCeRemoteDataAccess( _
        "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll", _
        "MyLogin", _
        "<password>", _
        "Data Source=MyDatabase.sdf")

    rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString, _
        RdaTrackOption.TrackingOnWithIndexes, "ErrorTable")

    ' or, try one of these overloads:
    ' rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString, _
    '     RdaTrackOption.TrackingOnWithIndexes)
    '
    ' rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString)

Catch
    ' Handle errors here
    '
Finally
    ' Dispose of the RDA object
    '
    rda.Dispose()
End Try
// Connection String to the SQL Server
//
string rdaOleDbConnectString = "Data Source=MySqlServer;Initial Catalog=AdventureWorks; " +
    "User Id=username;Password = <password>";

// Initialize RDA Object
//
SqlCeRemoteDataAccess rda = null;

try
{
    // Try the Pull Operation
    //
    rda = new SqlCeRemoteDataAccess(
        "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll",
        "MyLogin",
        "<password>",
        "Data Source=MyDatabase.sdf");

    rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString,
        RdaTrackOption.TrackingOnWithIndexes, "ErrorTable");

    // or, try one of these overloads:
    //
    // rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString,
    //     RdaTrackOption.TrackingOnWithIndexes);
    //
    // rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString);
}
catch (SqlCeException)
{
    // Handle errors here
    //
}
finally
{
    // Dispose of the RDA object
    //
    rda.Dispose();
}

執行緒安全性

任何公用靜態 (共用 在 Microsoft Visual Basic) 此型別的成員具備執行緒安全。不保證任何執行個體成員安全執行緒。

平台

開發平台

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
版本資訊
.NET Framework 及 NET Compact Framework
支援於 3.5
.NET Framework
支援於 3.0
.NET Compact Framework 及 .Net Framework
支援於 2.0

另請參閱

參考

SqlCeRemoteDataAccess Class
SqlCeRemoteDataAccess Members
System.Data.SqlServerCe Namespace