1

In my code two tables are connected and is working fine in local Host.but while i connect the same code to live the code is not working.

Connection String:

string constr = ConfigurationManager.ConnectionStrings["strconstr"].ConnectionString;

string constr = ConfigurationManager.ConnectionStrings["constrHOS"].ConnectionString;


 private void BindContactPerson(string hdnHospitalContactPersonID)
    {
        BD_Hospital iHospital = new BD_Hospital();
        string constr = ConfigurationManager.ConnectionStrings["constrHOS"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT D.DepartmentName,DS.DesignationName,hc.ContactPersonName,hc.ContactPersonAddress,hc.Mobile,hc.Phone,hc.AadhaarCardNo FROM HospitalContactPersonDeatils hc LEFT JOIN VAN_SETTING.[dbo].[Department] D ON D.DepartmentID =hc.DepartmentID LEFT JOIN VAN_SETTING.[dbo].[Designation] DS ON DS.DesignationID =hc.DesignationID where HospitalID='" + hdnHospitalContactPersonID + "'    ", con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    gvCustomers.DataSource = dt;
                    gvCustomers.DataBind();
                }
            }
        }
    }

Error Image:

**ERROR IMAGE**

2 Answers2

0

Generally its a port issue may be blocked by firewall, so to check we use a telnet command from the application server to the database server like following :

In windows command enter :

telnet database_ip_address_or_host_name port

Example for Sql server case :

telnet 192.168.1.1 1433

So to fix the issue you have to :

  1. Open database port in the database server
  2. Ensure no firewall is blocking your application in the application server to connect to the database

how to open port in windows

Korteby Farouk
  • 629
  • 7
  • 14
0

Sounds like there is an issue with the mapping between the application pool service account and the SQL login, or possibly an issue with the mapping between the SQL login and the SQL user accounts.

The simplest way to troubleshoot this is to sign on as the service account identity under which your web site's application pool is running. Once you are signed on, try to open SQL Server Management Console and attempt to access the database using integrated authentication. Whatever error you see there will be the same error that your web site is experiencing.

More info can be found in this question.

If you don't know what an application pool service account is, try this article.

Click here if you don't know the difference between a SQL login and a SQL user.

John Wu
  • 50,556
  • 8
  • 44
  • 80