Hey people,

I have a simple application which inserts data into database. The database is located on a remote machine.
However this machine(which has SQL) has a router installed. My pc(which has application) can find this machine's
IP address by using a code. Everything is okay till this stage.
Now when I try to insert data into DB it gives me error "No Such Host Found". As these machines are connected through
same router, so i need to ask that do i have switch on internet everytime I try to insert data Or is there any other way
around this problem?

Please help

Thanks and regards
Ajinkya

Please take a look at this code and tell me if I am wrong on logic part.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Data.SqlClient;

namespace WindowsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        //public string s;
        private void button1_Click(object sender, EventArgs e)
        {
            //try
            //{
                string goog = "Blackgold";
            //IPAddress[] addresslist = Dns.GetHostAddresses(goog);

                string vip = System.Net.Dns.GetHostEntry(goog).AddressList[0].ToString();
                string strr = "Data Source=" + vip + " ;Network Library = DBMSSOCN;Initial Catalog=MIS;Integrated Security=True";
                SqlConnection con1 = new SqlConnection(strr);
                con1.Open();

                if (con1.State.Equals(ConnectionState.Open))
                {

                    //try
                    //{

                        string qry = "Insert into TestT values('" + textBox1.Text + "','" + textBox2.Text + "')";
                        SqlCommand cmd = new SqlCommand(qry, con1);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("OK!");
                        con1.Close();
                    //}
                    //catch (Exception ex)
                    //{
                    //    MessageBox.Show("Application could not establish connection to the server!");
                    //    MessageBox.Show(ex.ToString());
                    //}
                }

                else
                {
                    MessageBox.Show("Application could not establish connection to the server!");
                }
            //}
            //catch (Exception exx)
            //{
                //MessageBox.Show("Application could not establish connection to the server!");
                //MessageBox.Show(exx.ToString());
            //}
        }
    }
}

Please take a look at this code and tell me if I am wrong on logic part.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Data.SqlClient;

namespace WindowsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        //public string s;
        private void button1_Click(object sender, EventArgs e)
        {
            //try
            //{
                string goog = "Blackgold";
            //IPAddress[] addresslist = Dns.GetHostAddresses(goog);

                string vip = System.Net.Dns.GetHostEntry(goog).AddressList[0].ToString();
                string strr = "Data Source=" + vip + " ;Network Library = DBMSSOCN;Initial Catalog=MIS;Integrated Security=True";
                SqlConnection con1 = new SqlConnection(strr);
                con1.Open();

                if (con1.State.Equals(ConnectionState.Open))
                {

                    //try
                    //{

                        string qry = "Insert into TestT values('" + textBox1.Text + "','" + textBox2.Text + "')";
                        SqlCommand cmd = new SqlCommand(qry, con1);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("OK!");
                        con1.Close();
                    //}
                    //catch (Exception ex)
                    //{
                    //    MessageBox.Show("Application could not establish connection to the server!");
                    //    MessageBox.Show(ex.ToString());
                    //}
                }

                else
                {
                    MessageBox.Show("Application could not establish connection to the server!");
                }
            //}
            //catch (Exception exx)
            //{
                //MessageBox.Show("Application could not establish connection to the server!");
                //MessageBox.Show(exx.ToString());
            //}
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.