locked
用RDA把sql与sqlce数据同步问题 RRS feed

  • 问题

  • 其实我只想把本地表数据push到服务器,不用pull数据下来,但是不能功能。当我pull的时候总是提示“无法使用给定的连接字付串打开SQL SERVER”

    以下是我的代码。我真的不知道错在哪里。希望大家指出错误。谢谢

      public void Pull(string localTableName, string sqlSelectString, string oleDBConnectionString, RdaTrackOption trackOption)
            {
                // Connection String to the SQL Server
                string rdaOleDbConnectString = "Provider=sqloledb;Data Source=10.102.197.20;Initial Catalog=Example;Integrated Security=False;User ID=sa;password=;";
                string localString = (@"Data Source =\My Documents\Example.sdf");
               
                SqlCeRemoteDataAccess rda = null;

                try
                {
                    // Try the Pull Operation

                    rda = new SqlCeRemoteDataAccess();
                   // rda = new SqlCeRemoteDataAccess( "http://10.102.197.20/sqlce3/sqlcesa30.dll", localString);
                    rda.InternetLogin = "";
                    rda.InternetPassword = "";
                  rda.InternetUrl = "http://10.102.197.20/sqlce3/sqlcesa30.dll";
                    rda.LocalConnectionString = localString;

                    rda.Pull("worktime1", "SELECT * FROM WorkTime where 1<>1", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes, "ErrorTable");
                    MessageBox.Show("ok");

                }
                catch (SqlCeException e)
                {
                   MessageBox.Show(e.Message);
                }
                finally
                {
                    rda.Dispose();
                }
            }

            //rda.push方法将 SQL Server CE 跟踪提取表中的更改传送回原始 SQL Server 表。
            public void Push(string localTableName, string oleDBConnectionString, RdaBatchOption batchOption)
            {
                 string rdaOleDbConnectString = "Provider=SQLOLEDB; Data Source=10.102.197.20;Initial Catalog=Example;Integrated Security=False;User ID=sa;password=;";
                 string localString = (@"Data Source =\My Documents\Example.sdf");

                // Initialize RDA Object

                SqlCeRemoteDataAccess rda = null;

                try
                {
                    rda = new SqlCeRemoteDataAccess();
                    rda.LocalConnectionString = localString;
                    rda.InternetLogin = "MyLogin";
                    rda.InternetPassword = " ";
                    rda.InternetUrl = "http://10.102.197.20/sqlce3/sqlcesa30.dll";
                    rda.LocalConnectionString = (@"Data Source =\My Documents\Example.sdf");


                    rda.Push("WorkTime1", rdaOleDbConnectString, RdaBatchOption.BatchingOn);
                    MessageBox.Show("success");
                    // "insert into WorkTime1 select * from WorkTime  ",

                }
                catch (SqlCeException e)
                {
                    MessageBox.Show(e.Message);
                   // ShowErrors(e);
                }
                finally
                {
                    rda.Dispose();
                }
            }

    2007年9月12日 4:00

答案

  •  

    使用RDA时,需要注意的是,所有需要Push的表都必须先通过Pull操作把表结构抓下来,进行操作之后,再Push回去。所以如果Pull失败,Push肯定会失败。

    首先确认你OLEDB的连接字符串正确,在本机上能够使用这个连接字符串访问数据库。这是最容易出问题的地方。

    如果确认没问题,再将RdaTrackOption.TrackingOnWithIndexes改为RdaTrackOption.TrackingOn,因为表结构的原因,也可能会造成Index无法复制。

     

    2007年10月9日 4:44