다음을 통해 공유


방법: RDA 개체를 사용하여 데이터 밀어넣기(프로그래밍 방식)

이 항목에서는 SqlCeRemoteDataAccess 클래스를 사용하여 Microsoft SQL Server Compact 3.5(SQL Server Compact 3.5) 데이터베이스에서 Microsoft SQL Server 데이터베이스로 데이터를 밀어넣는 방법에 대해 설명합니다. SqlServerCe 네임스페이스 사용 방법은 SqlServerCe 네임스페이스 참조 설명서를 참조하십시오.

RDA(Remote Data Access)를 사용하여 데이터를 밀어넣으려면 다음과 같이 하십시오.

  1. SqlCeRemoteDataAccess 개체를 초기화하고 연결 속성을 설정합니다.

    SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess("https://www.adventure-works.com/sqlmobile/sqlcesa35.dll", "Data Source=MyDatabase.sdf");
    
  2. SQL Server 데이터베이스에 데이터와 연결 문자열을 밀어넣을 로컬 SQL Server Compact 3.5 테이블 이름을 전달하여 Push 메서드를 호출합니다. 또한 사용할 일괄 처리 옵션을 지정할 수도 있습니다.

    rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn);
    

이 예에서는 SQL Server Compact 3.5 데이터베이스의 MyLocalTable 테이블에서 MySqlServer라는 SQL Server 인스턴스의 AdventureWorks 데이터베이스로 데이터를 밀어넣는 방법을 보여 줍니다.

string rdaOleDbConnectString = @"Provider=SQLOLEDB; Data Source=MySqlServer;
    Initial Catalog=AdventureWorks; User Id=username;
    Password = <enterStrongPasswordHere>";

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

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

            rda.InternetLogin = "MyLogin";
            rda.InternetPassword = "<enterStrongPasswordHere>";

            rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn);

            // or, try this overload:
            //
            // rda.Push("MyLocalTable", rdaOleDbConnectString);
        }
        catch (SqlCeException)
        {
            // Handle errors here
            //
        }
        finally
        {
            // Dispose of the RDA Object
            //
            rda.Dispose();
        }
Dim rdaOleDbConnectString As String = _
 "Provider=SQLOLEDB; "Data Source=MySqlServer;Initial Catalog=AdventureWorks; "
            "User Id=username;Password = <enterStrongPasswordHere>"

        ' Initialize RDA Object
        '
        Dim rda As SqlCeRemoteDataAccess = Nothing

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

            rda.InternetLogin = "MyLogin"
            rda.InternetPassword = "<enterStrongPasswordHere>"

            rda.Push("MyLocalTable", rdaOleDbConnectString, RdaBatchOption.BatchingOn)

            ' or, try this overload:
            '
            ' rda.Push("MyLocalTable", rdaOleDbConnectString)

        Catch
            ' Handle errors here
            '
        Finally
            ' Dispose of the RDA Object
            '
            rda.Dispose()
        End Try

참고 항목

관련 자료

RDA(Remote Data Access) 소개
클라이언트에서 서버로 데이터 밀어넣기

도움말 및 정보

지원 받기(SQL Server Compact 3.5 서비스 팩 1)