Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 后台工作程序未使用Oracle连接_.net_Wpf_Backgroundworker - Fatal编程技术网

.net 后台工作程序未使用Oracle连接

.net 后台工作程序未使用Oracle连接,.net,wpf,backgroundworker,.net,Wpf,Backgroundworker,我有一个奇怪的问题,我想从Oracle(在线数据库)获取记录,并插入和更新MySQL数据库,这是一个离线数据库,如果故障转移MySQL数据库启动功能。我必须将主要记录从Oracle更新到MySql,这样,如果离线数据库在游戏中启动,它就会在其中包含所有相关的同步数据 我已经使用BackgroundWorker类编写了代码,以便可以将其保存在单独的线程中 以下是代码,请查看 代码 使用Oracle.DataAccess.Client; 使用制度; 使用System.Collections.Gene

我有一个奇怪的问题,我想从Oracle(在线数据库)获取记录,并插入和更新MySQL数据库,这是一个离线数据库,如果故障转移MySQL数据库启动功能。我必须将主要记录从Oracle更新到MySql,这样,如果离线数据库在游戏中启动,它就会在其中包含所有相关的同步数据

我已经使用BackgroundWorker类编写了代码,以便可以将其保存在单独的线程中 以下是代码,请查看

代码

使用Oracle.DataAccess.Client;
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Linq;
使用系统文本;
使用系统线程;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
使用System.Data.EntityClient;
使用系统数据;
名称空间医院系统
{
/// 
///HospitalSync.xaml的交互逻辑
/// 
公共部分类HospitalSync:窗口
{
公共背景工作者;
公共记录;
公立医院
{
初始化组件();
}
公共整数计算百分比(当前整数)
{
整数百分比=(整数)(当前/总记录)*100;
回报率;
}
公共无效SyncDataFromKPT(对象发送方,DoWorkEventArgs e)
{
MedEntities Db=新的MedEntities();
使用(OracleConnection=newOracleConnection(Db.Database.connection.ConnectionString))
{
DataTable RecordsToUpdateTable=新DataTable();
string SqlCommand=“选择*来自medsec.vu注册\u修改”;
使用(OracleCommand cmd=新的OracleCommand(SqlCommand,连接))
{
OracleDataAdapter=新的OracleDataAdapter(SqlCommand,connection);
adapter.SelectCommand.CommandType=CommandType.Text;
adapter.Fill(RecordsToUpdateTable);
如果(RecordsToUpdateTable.Rows.Count>0)
{

对于(int j=0;j,这个问题是在@Markus的帮助下解决的。 多谢各位


这是我使用32位客户端库并在64位上调试时遇到的平台问题。

是否收到错误消息?Db.Database.Connection.ConnectionString是否有效?我怀疑需要先设置Connection属性。您应该尝试以其他方式获取连接字符串(无连接字符串,无连接,因此无法使用连接获取连接字符串)。我在以前的应用程序中使用相同的逻辑获取了连接字符串,它作为一个符咒工作。@当我删除整个using块时,请标记它的执行者注册BackgroundWorker的,并检查RunWorkerCompletedEventArgs是否包含任何异常或错误Errors@Markus你说得对。Oracle.DataAc出现错误cess库我正在处理64位应用程序,DLL是32位应用程序。我将项目属性更改为32位应用程序,它非常有用。感谢您的帮助
using Oracle.DataAccess.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.EntityClient;
using System.Data;

namespace HospitalSystem
{
    /// <summary>
    /// Interaction logic for HospitalSync.xaml
    /// </summary>
    public partial class HospitalSync : Window
    {
       public BackgroundWorker Worker;
       public int TotalRecords;

        public HospitalSync()
        {
            InitializeComponent();
        }

        public int CalculatePercentage(int Current)
        {
            int Percentage = (int) (Current / TotalRecords) * 100;
            return Percentage;
        }

        public void SyncDataFromKPT(object sender, DoWorkEventArgs e)
        {
            MedEntities Db = new MedEntities();

            using (OracleConnection connection = new OracleConnection(Db.Database.Connection.ConnectionString))
            {
                DataTable RecordsToUpdateTable = new DataTable();
                string SqlCommand = "SELECT * FROM medsec.vu_registration_modify";
                using (OracleCommand cmd = new OracleCommand(SqlCommand, connection))
                {
                    OracleDataAdapter adapter = new OracleDataAdapter(SqlCommand, connection);
                    adapter.SelectCommand.CommandType = CommandType.Text;
                    adapter.Fill(RecordsToUpdateTable);
                    if (RecordsToUpdateTable.Rows.Count > 0)
                    {
                        for (int j = 0; j <= RecordsToUpdateTable.Rows.Count; j++)
                        {
                            RecCountTotal.Content = j + 1;
                            CalculatePercentage(j);
                        }

                    }

                }

            }

        }

        public void ProcessCompleted(object sender, ProgressChangedEventArgs e)
        {
            UpdateBar.Value = e.ProgressPercentage;
        }

        public void InitializeWorker()
        {
            Worker = new BackgroundWorker();
            Worker.WorkerReportsProgress = true;
            Worker.DoWork += new DoWorkEventHandler(SyncDataFromKPT);
            Worker.ProgressChanged += new ProgressChangedEventHandler(ProcessCompleted);
            Worker.RunWorkerAsync(Worker);  
        }   

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            InitializeWorker();   
        }
    }
}