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 和更高版本)针对网站数据库用途进行了优化。

在使用 ASP.NET 为同步方案创建 SQL Server Compact 3.5 数据库的应用方案中,可将 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 命名空间