共用方式為


SqlCeRemoteDataAccess 類別

初始化 SqlCeRemoteDataAccess 物件的新執行個體。如需有關「遠端資料存取」的詳細資訊,請參閱<使用遠端資料存取 (RDA)>。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
Public NotInheritable Class SqlCeRemoteDataAccess _
    Implements IDisposable
'用途
Dim instance As SqlCeRemoteDataAccess
public sealed class SqlCeRemoteDataAccess : IDisposable
public ref class SqlCeRemoteDataAccess sealed : IDisposable
[<SealedAttribute>]
type SqlCeRemoteDataAccess =  
    class
        interface IDisposable
    end
public final class SqlCeRemoteDataAccess implements IDisposable

備註

SQL Server Compact 3.5 目前並未最佳化,無法當做網站的資料庫。依預設,在 SQL Server Compact 3.5 中會封鎖從 ASP.NET 連接之應用程式的連線。SQL Server Compact 3.5 最適合做為應用程式中的內嵌資料庫。使用 SQL Server Compact 3.5 做為網站的資料庫需要支援多使用者與並行資料變更。這可能會造成效能問題。因此,並不支援這些狀況。其他版本的 SQL Server (包括 SQL Server 2005 Express Edition 和更新版本) 都已最佳化,可以當做網站的資料庫。

SQL Server Compact 3.5 可以在使用 ASP.NET 建立 SQL Server Compact 3.5 資料庫 (適用於同步處理案例) 的應用程式案例中搭配 ASP.NET 使用。使用下列程式碼以變更 SQL Server Compact 3.5 的預設行為,以便在 ASP.NET 中運作。

AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)

範例

下列範例顯示如何初始化 SqlCeRemoteDataAccess 物件的新執行個體。

' 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();
}

繼承階層

System. . :: . .Object
  System.Data.SqlServerCe..::..SqlCeRemoteDataAccess

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

請參閱

參考

SqlCeRemoteDataAccess 成員

System.Data.SqlServerCe 命名空間