您的位置:程序门 -> .net技术 -> c#



我用c# 写的程序出现假死.没有响应可能我的数据还在导.进程里显示程序没有响应是怎么回事呀.


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


我用c# 写的程序出现假死.没有响应可能我的数据还在导.进程里显示程序没有响应是怎么回事呀.[已结贴,结贴人:gaoxinao]
发表于:2007-03-02 17:24:15 楼主
我是想从一台sql服务器上导到别一台服务器上数据量很大.请各位多多指点呀.在线急等.


namespace   windowsapplication4
{
        public   partial   class   daoru   :   form
        {
                public   string   connstr2   =@ "server=127.0.0.1;uid=sa;pwd=1234ee;database=ewer; ";//本地服务器
                public   string   connstr   =   @ "server=badsf;uid=sa;pwd=2123123;database=werwe; ";//远程服务器数据源
                public   string   cladd= " ";
                public   daoru()

                {
                        initializecomponent();
                }

                private   void   button2_click(object   sender,   eventargs   e)
                {
                        string   testsql= " ";
                        string   strins2= " ";
                        string   top2   =   " ";
                        if   (textbox1.text.tostring()   !=   "0 "   &&   textbox1.text.tostring()   !=   " ")
                        {
                                top2   =   @ "   top   "   +   textbox1.text.tostring();


                                if   (combobox1.text.tostring()   ==   "hy ")
                                {

                                        testsql   =   @ "select   "   +   top2   +   "   *   from   [smss_sendmsg]   where   convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120)   and   信息分类= 'hy ' ";
                                        strins2   =   @ "insert   into   info_cat   (title,add1,add2,tel,st_date,adddate,end_date,audit,upclass,cont,userid,cat_class)   values   ";
                                        cladd   =   "info_cat ";
                                }
                                if   (combobox1.text.tostring()   ==   "hy ")
                                {

                                        testsql   =   @ "select     "+top2+ "   *   from   [smss_sendmsg]   where   convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120)   and   信息分类= 'hy ' ";
                                        strins2   =   @ "insert   into   info_goods   (title,add1,add2,tel,sg_date,senddate,enddate,audit,upclass,cont,userid)   values   ";
                                        cladd   =   "info_goods ";
                                }


                                daoru5(testsql,   strins2,   connstr,   connstr2);
                        }
                        else   {
                                messagebox.show( "最大导入量不能为0或为空! ");

                        }
                }

                private   void   button1_click(object   sender,   eventargs   e)
                {
                        string   testsql   =   @ "select   *   from   [smss_sendmsg]   where   convert(varchar(10),发送时间1,120)=convert(varchar(10),getdate(),120) ";
                        gu(testsql,connstr);
                }


                public   void   gu(string   strf,   string   odb)
                {
                        try
                        {
                                listbox1.items.clear();            
                                sqlconnection   connf   =   new   sqlconnection();
                                connf.connectionstring   =   @odb;
                                sqldataadapter   myadapter   =   new   sqldataadapter();
                                connf.open();
                                sqlcommand   sqlcommand   =   new   sqlcommand(strf,   connf);
                                sqlcommand.connection   =   connf;
                                sqldatareader   readdata   =   null;


                                readdata=sqlcommand.EXECutereader();
                                      messagebox.show(connf.state.tostring());
                                      int   i   =   0;
while(readdata.read()==true)
                                        {
                                                label1.text   =   @readdata[ "信息 "].tostring();
                                                label5.text   =   i.tostring();
                                              listbox1.items.add(readdata[ "编号 "].tostring()   +   readdata[ "信息 "].tostring()   +   readdata[ "出发地 "].tostring()   +   readdata[ "来源 "].tostring()   +   "       发布时间: "   +   readdata[ "发送时间1 "].tostring()   +   "电话: "   +   readdata[ "电话号码 "].tostring());
                                              label5.refresh();
                                                label1.refresh();
                                                i   =   i   +   1;
                                        }
connf.close();

                        }
                        catch   (exception   e)
                        {
                                messagebox.show(e.tostring());
                        }
            }
                public   void   daoru5(string   strf,string   strins,   string   odb,string   odb2)
                {
                        try
                        {
                                listbox1.items.clear();
                                sqlconnection   connf   =   new   sqlconnection();
                                connf.connectionstring   =   @odb;
                                sqldataadapter   myadapter   =   new   sqldataadapter();
                                connf.open();
                                sqlcommand   sqlcommand   =   new   sqlcommand(strf,   connf);
                                sqlcommand.connection   =   connf;
                                sqldatareader   readdata   =   null;


                                readdata   =   sqlcommand.EXECutereader();
                                int   i   =   0;
                                                        sqlconnection   connf2   =   new   sqlconnection();
                                connf2.connectionstring   =   odb2;
                           
                              while   (readdata.read()   ==   true)
                                {
                                     
                               
                                        connf2.open();
                     
                                        string   strins2;
                                        if   (combobox1.text.tostring()   ==   "hy ")
                                        {
                                              strins2   =   strins   +   @ "( ' "   +   readdata[ "信息 "].tostring()   +   " ', ' "   +   readdata[ "出发地 "].tostring()   +   " ', ' "   +   readdata[ "出发地 "].tostring()   +   " ', ' "   +   readdata[ "电话号码 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ',1,2, ' "   +   readdata[ "信息 "].tostring()   +   " ', ' "   +   combobox3.text.tostring()   +   " ')   ";
                                        }
                                        else   {
                                                system.random   r   =   new   random();
                                                int   yourandom   =   r.next(1,   4);
                                                strins2   =   strins   +   @ "( ' "   +   readdata[ "信息 "].tostring()   +   " ', ' "   +   readdata[ "出发地 "].tostring()   +   " ', ' "   +   readdata[ "出发地 "].tostring()   +   " ', ' "   +   readdata[ "电话号码 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ', ' "   +   readdata[ "发送时间1 "].tostring()   +   " ',1,2, ' "   +   readdata[ "信息 "].tostring()   +   " ', ' "   +   combobox3.text.tostring()   +   " ', "   +   yourandom.tostring()+   ")   ";

                                        }
                                                sqlcommand   inst2   =   new   sqlcommand(strins2,   connf2);
                            inst2.EXECutenonquery();
                            label1.text   =   @readdata[ "信息 "].tostring();
                                                listbox1.items.add(readdata[ "编号 "].tostring()   +   readdata[ "信息 "].tostring()   +   readdata[ "出发地 "].tostring()   +   readdata[ "来源 "].tostring()   +   "       发布时间: "   +   readdata[ "发送时间1 "].tostring()   +   "电话: "   +   readdata[ "电话号码 "].tostring());
                                                listbox1.refresh();
                                                label5.text   =   i.tostring();
                                                label5.refresh();
                                                label1.refresh();
                                          i   =   i   +   1;
    }
                                     
                                  connf2.close();
                        }
                                connf.close();
                                messagebox.show( "导入成功! ");
                          }
                        catch   (exception   e)
                        {
                                messagebox.show(e.tostring());
                        }


                }
        }
}


发表于:2007-03-02 17:27:561楼 得分:5
a)最好另外开进程显示进度;
b)否则不要实时显示进度,还有用strinfbuilder。
发表于:2007-03-02 17:28:222楼 得分:0
不是死机,是你的程序运行时间太长,你等它运行完就好了!
处理这种情况的办法是用异步操作或线程
发表于:2007-03-02 17:29:123楼 得分:5
你把导数据放一个线程里,它是太忙了,我也遇到过这个问题
发表于:2007-03-02 17:34:594楼 得分:0
用线程去跑这个    
参考多线程编程
发表于:2007-03-02 17:49:155楼 得分:20
这样   你在每个   数据量大的while循环最后一句写上
application.doevents();
这样界面就不会死了
发表于:2007-03-02 22:37:016楼 得分:0
有没有多线程的例子呀?简单点的老总急要呀.请各位多多帮助了.
发表于:2007-03-02 22:45:517楼 得分:15
1.改用存储过程来导;
2.加入事务处理机制.
发表于:2007-03-02 23:04:118楼 得分:0
能帮我写一下存储过程的代码吗?谢谢了.
发表于:2007-03-04 17:06:149楼 得分:35

application.doevents();
也可以用存储过程.


快速检索

最新资讯
热门点击