unable to connect to the remote server

30 views
Skip to first unread message

mansuri shahrukh

unread,
Jun 24, 2016, 3:03:24 PM6/24/16
to SolrNet
I am using below code to indexing a data and that a WPF application for solrnet and its give  an error on the solr.add result at last please give me some solution for it 





using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data.Sql;
using Microsoft.Practices.ServiceLocation;
using System.Data;
using SolrNet;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.OleDb;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Web;
using System.Xml.Serialization;
using SolrNet.Commands.Parameters;
using SolrNet.Exceptions;
using SolrNet.Impl;
using SolrNet.Attributes;

namespace WpfApplication49
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        public class TrackInfo
        {

            [SolrField("title")]
            public string title1 { get; set; }

            [SolrField("author")]
            public string author1 { get; set; }

            [SolrField("accessionNo")]
            public string accessionNo1 { get; set; }


            [SolrField("location")]
            public string location1 { get; set; }


            [SolrField("classNo")]
            public string classNo1 { get; set; }


            [SolrField("status")]
            public string status1 { get; set; }

            [SolrField("meetingName")]
            public string meetingName1 { get; set; }

            [SolrField("uniformtitle")]
            public string uniformtitle1 { get; set; }

            [SolrField("publisher")]
            public string publisher1 { get; set; }



        }

        public string GetTagSbFldSQL()
        {
            string strTagSbFld = "";
            DataSet ResultDS = new DataSet();
            strTagSbFld = "select  b.FValue as title,  E.FValue as author, l.p852 as accessionNo, l.a852 as location,l.k852 as classNo,l.status, w.fvalue as meetingName , k.FValue as subtitle,u.FValue as yearofpublication, c.FValue as ISBN, d.FValue as issn, k.FValue as subtitle,  f.FValue as roleofauthor, g.FValue as editor,  i.FValue as publisherPlace, h.FValue as publisher, x.FValue AS Series,  j.FValue as pyhsicaldescription, o.FValue as corporatename,v.FValue as Uniformtitle ,l.DateofAcq as AccessionDate, m.FValue as Note , l.Budget as Budget,  l.m852 as bookNo ,l.Price as Price,l.t852 as CopyNo,l.Supplier  as supplier ,l.b852 as collectionttype, l.Material As materials from Biblidetails b left join Biblidetails c on  b.RecID = c.RecID and c.Tag = 020 and c.SbFld = 'a'left join Biblidetails d on  b.RecID = d.RecID and d.tag = 022 and d.SbFld = 'a'left join Biblidetails w on  b.RecID = w.RecID and w.tag = 111 and w.SbFld = 'a'left join Biblidetails e on  b.RecID = e.RecID and e.Tag = 100 and e.SbFld = 'a'left join Biblidetails f on  b.RecID = f.RecID and f.Tag = 100 and f.SbFld = 'e' left join Biblidetails g on  b.RecID = g.RecID and g.Tag = 250 and g.SbFld = 'a'left join Biblidetails h on  b.RecID = h.RecID and h.Tag = 260 and h.SbFld = 'b'left join Biblidetails i on  b.RecID = i.RecID and i.Tag = 260 and i.SbFld = 'a'left join Biblidetails u on  b.RecID = u.RecID and u.Tag = 260 and u.SbFld = 'c'left join Biblidetails j on  b.RecID = j.RecID and j.Tag = 300 and j.SbFld = 'a' left join Biblidetails k on  b.RecID = k.RecID and k.Tag = 245 and k.SbFld = 'b' left join Biblidetails m on  b.RecID = m.RecID and m.Tag = 500 and m.SbFld = 'a' left join Biblidetails o on  b.RecID = o.RecID and o.Tag = 110 and o.SbFld = 'a'left join Biblidetails x on  b.RecID = x.RecID and x.Tag = 440 and x.SbFld = 'a'left join Biblidetails v on  b.RecID = v.RecID and v.Tag = 630 and v.SbFld = 'a'  inner join location l  on b.RecID = l.RecID   where b.Tag = 245 and b.SbFld = 'a'  ";
            return strTagSbFld;

        }


        private void connect_Click(object sender, RoutedEventArgs e)
        {

            Startup.Init<TrackInfo>("http://localhost:8983/solr");

            int intCount = 0;

            ISolrOperations<TrackInfo> solr = ServiceLocator.Current.GetInstance<ISolrOperations<TrackInfo>>();
            // Instanciate the metadata object 

            // Loop through the SQL Server Database then add a solr record 

            // Create a connection object and data adapter 
            string connetionString = null;

            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand cmd;
            connetionString = "Data Source='" + servername.Text + "';Initial Catalog='" + database.Text + "';User ID='" + username.Text + "';Password='" + password.Text + "'; CONNECTION TIMEOUT=120";


            SqlConnection conn = new SqlConnection(connetionString);

            DataSet BibliDS = new DataSet();
            DataSet DataDS = new DataSet();
            DataTable dt = default(DataTable);

            string strTagSbFld = null;
            strTagSbFld = GetTagSbFldSQL();

            conn.Open();


            adapter.SelectCommand = new SqlCommand(strTagSbFld, conn);
            adapter.SelectCommand.CommandTimeout = 0;
            adapter.Fill(DataDS);

            MessageBox.Show(connetionString);
            conn = new SqlConnection(connetionString);
            conn.Open();
            MessageBox.Show("CONNECTION DONE");
            var file = Directory.GetFiles("C:/Users/Shahrukh/Desktop/New folder (6)");
            MessageBox.Show("file");
            foreach (var s in file)
            {
                cmd = new SqlCommand(strTagSbFld, conn);
                MessageBox.Show("FOR LOOP IS ON HERE");
                DataTable dS = new DataTable();
                adapter.SelectCommand = new SqlCommand(strTagSbFld, conn);
                adapter.Fill(dS);
                // Loop to go through database, then add to Solr 
                foreach (DataRow dr in dS.Rows)
                {
                    intCount++;
                    TrackInfo tinfo = new TrackInfo();
                    tinfo.title1 = dr["title"].ToString();
                    tinfo.author1 = dr["author"].ToString();
                    tinfo.accessionNo1 = dr["accessionNo"].ToString();
                    tinfo.location1 = dr["location"].ToString();
                    tinfo.classNo1 = dr["classNo"].ToString();
                    tinfo.status1 = dr["status"].ToString();
                    tinfo.meetingName1= dr["meetingName"].ToString();
                    tinfo.uniformtitle1 = dr["uniformtitle"].ToString();
                    tinfo.publisher1 = dr["publisher"].ToString().Trim();
                    solr.Add(tinfo);  //here comes an error "unable to connect to remote server "
                }


                try
                {

                    solr.Commit();
                }
                catch (Exception)
                {

                    throw;

                }
                conn.Close();

            }

            // Clean up resources and return record count 


        }
    }
}

    

Mauricio Scheffer

unread,
Sep 6, 2016, 6:41:37 PM9/6/16
to SolrNet
 Startup.Init should only be called once at startup, but here it's being called in an event handler.
Reply all
Reply to author
Forward
0 new messages