﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Во время переподключения к квику вылетает ошибка</title>
  <id>~/topic/3494/vo-vremya-perepodklyucheniya-k-kviku-vyletaet-oshibka/</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-05-01T19:23:40Z</updated>
  <logo>https://stocksharp.com/images/logo.png</logo>
  <link href="https://stocksharp.com/handlers/atom.ashx?category=topic&amp;id=3494" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.com/posts/m/24752/</id>
    <title type="text">Когда переподключается коннектор возникает сообщение об ошибке что колонки таблиц уже добавлены и де...</title>
    <published>2013-03-23T23:06:36Z</published>
    <updated>2013-03-23T23:07:47Z</updated>
    <author>
      <name>Yegor Hi And</name>
      <uri>https://stocksharp.com/users/6061/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">Когда переподключается коннектор возникает сообщение об ошибке что колонки таблиц уже добавлены&lt;br /&gt;и действительно при первом подключении добавляются дополнительные колонки :&lt;br /&gt; _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestAskPrice);&lt;br /&gt; _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestBidPrice);&lt;br /&gt;&lt;br /&gt;Как сделать так что-бы не вылетало это &lt;br /&gt;Вся процедура подключения ниже в коде.&lt;br /&gt;Заранее благодарен&lt;br /&gt;&lt;br /&gt;&lt;div class="code"&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;div class="innercode"&gt;&lt;pre class="brush:csharp"&gt;
        {

            var guiListener = new GuiLogListener();

            _logManager.Listeners.Add(guiListener);


            if (_trader == null &amp;amp;&amp;amp; terminals.cbTerminals.Text != &amp;quot;&amp;quot;)
            {

                _trader = new QuikTrader(terminals.cbTerminals.Text) { SupportManualOrders = true };
                _trader.ReConnectionSettings.ExportTimeOutInterval = TimeSpan.FromSeconds(10);
                
                _trader.ReConnectionSettings.WorkingTime = _trader.ReConnectionSettings.WorkingTime = Exchange.Rts.WorkingTime; //.Test.WorkingTime;//

                _trader.ReConnectionSettings.ConnectionRestored += () =&amp;gt; this.GuiAsync(() =&amp;gt; 
                    {
                        //MessageBox.Show(this, &amp;quot;Соединение восстановлено&amp;quot;);
                        connect_disconect(&amp;quot;connected&amp;quot;);
                        start_copy();
                    }
                    );
                _trader.ReConnectionSettings.IsReStartExport = true;
                _trader.ConnectionError += error =&amp;gt; this.GuiAsync(() =&amp;gt; MessageBox.Show(this, error.ToString()));

                //_trader.Disconnected += new Action(_trader_Disconnected);

                Q_path = terminals.cbTerminals.Text;

                _trader.Connected += () =&amp;gt;
                {

                    try
                    {

                        _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestAskPrice);
                        _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestBidPrice);

                        //lbConn.Content = &amp;quot;1&amp;quot;;

                        _trader.StartExport();

                        if (SelectedPortfolio != null &amp;amp;&amp;amp; SelectedSecurity != null)//SelectedPortfolio
                        {
                            var myposition = _trader.GetPosition(SelectedPortfolio, SelectedSecurity).CurrentValue;
                           
                            this.GuiAsync(() =&amp;gt;
                            {
                                lbCPose2.Content = myposition;
                                
                            });

                        }

                    }//try
                    catch (Exception ee)
                    {

                        MessageBox.Show(&amp;quot;Произошла ошибка связи и Квиком 1 &amp;quot; + ee.ToString());

                    }

                };

                

                
                _trader.NewSecurities += securities =&amp;gt; this.GuiAsync(() =&amp;gt;
                {
                    try
                    {
                        cbSecuritites.ItemsSource = _trader.Securities;
                        cbSecuritites.SelectedIndex = 0;
                       
                    }//try
                    catch (Exception ee)
                    {
                        MessageBox.Show(&amp;quot;Произошла ошибка связи и Квиком 2 &amp;quot; + ee.ToString());
                       

                        connect_disconect(&amp;quot;0&amp;quot;);

                    }

                });


                _trader.SecuritiesChanged += security =&amp;gt; this.GuiAsync(() =&amp;gt;
                {
                    try
                    {
                        if (_trader != null)
                        {
                            cbSecuritites.ItemsSource = _trader.Securities;

                            if (SelectedSecurity != null)
                            {

                                label2.Content = SelectedSecurity.BestBid.Price.ToString();
                                lbBestAsk.Content = SelectedSecurity.BestAsk.Price.ToString();
                            }
                        }
                    }//try
                    catch (Exception ee)
                    {

                        if (_trader != null)
                        {
                            MessageBox.Show(&amp;quot;Произошла ошибка связи и Квиком 2.1 &amp;quot; + ee.ToString());

                            connect_disconect(&amp;quot;0&amp;quot;);

                        }
                    }

                });

                _trader.NewPortfolios += portfolios =&amp;gt; this.GuiAsync(() =&amp;gt;
                {
                    try
                    {
                        Portfolios.ItemsSource = _trader.Portfolios; //cbSecuritites.ItemsSource = _trader.Securities;//  _trader.StartExport();
                        Portfolios.SelectedIndex = 1;
                        if (SelectedPortfolio != null)// &amp;amp;&amp;amp; SelectedSecurity != null)//SelectedPortfolio SelectedSecurity);//
                        {
                            //  _trader.RegisterMarketDepth(SelectedSecurity);
                        }
                        //lbConnected.Content = &amp;quot;Connected&amp;quot;;
                        connect_disconect(&amp;quot;connected&amp;quot;);
                        tbVolume.Text = &amp;quot;1&amp;quot;;
                        //tbDelta.Text = &amp;quot;0&amp;quot;;
                        btConnect.Background = default_but_color;
                        // Connect_.Background = default();//    System.Windows.Media.LinearGradientBrush;// Brushes.LightPink;
                        // register_MDs();
                    }//try
                    catch (Exception ee)
                    {
                        MessageBox.Show(&amp;quot;Произошла ошибка связи и Квиком 3 &amp;quot; + ee.ToString());
                    }

                });


                _trader.PositionsChanged += positions =&amp;gt; this.GuiAsync(() =&amp;gt;
                {
                    //конркетная позиция по конкретному портфелю инструменту
                    if (SelectedPortfolio != null &amp;amp;&amp;amp; SelectedSecurity != null)//SelectedPortfolio
                    {
                        var myposition = positions.FirstOrDefault(p =&amp;gt; p.Portfolio == SelectedPortfolio &amp;amp;&amp;amp; p.Security == SelectedSecurity);//SelectedPortfolio
                        if (myposition != null)
                        {
                            lbCPose2.Content = myposition.CurrentValue;
                            //on_change_pose();
                        }

                    }

                });

                try
                {
                    _trader.Connect();
                }//try
                catch (Exception ee)
                {
                    MessageBox.Show(&amp;quot;Произошла ошибка связи и Квиком 5&amp;quot; + ee.ToString());
                    // return;
                }

                _trader.ConnectionError += errror =&amp;gt; this.GuiAsync(() =&amp;gt;
                {
                    if (_trader != null)
                    {
                       // _trader.Dispose();
                        connect_disconect(&amp;quot;0&amp;quot;);
                        //_trader = null;
                        //clear_all();
                    }
                });

            }
            else
            {
                if (_trader != null &amp;amp;&amp;amp; _trader.IsConnected)
                {
                   // if (_trader != null)  _trader.Dispose();
                    connect_disconect(&amp;quot;0&amp;quot;);
                   // _trader = null;
                    clear_all();
                }
            }
           

        }&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>