Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code.. Im just checking weather database connected or not...


<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/>

--------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;


namespace dbc
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connectionString="Data Source=USER-PC;Initial Catalog=master;Integrated Security=True";
            SqlConnection conn=new SqlConnection(connectionString);
            conn.Open();
            Response.Write("hi");
            conn.Close();
        }
    }
}


----------------
But i got the error like this... how can i resolve this error..

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Posted
Comments
sandy pathak 25-Jul-14 3:02am    
Check Data Source property value in connection string

1 solution

Check this answer[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900