Click here to Skip to main content
15,031,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)



C#
public void store(string a)
        {
            SqlConnection connect=null;

            connect = new SqlConnection("server= . ;  initial catalog=Student_Tracker DB ; integrated security= true ;");
            connect.Open();
            connect = new SqlConnection("insert into dbo.Student_Details (named) values (a)");
            connect.Close();
        }



This is the exception which i ma getting on the "connect.Open()" .

Thanks in advance :)
Posted

I think you add to your server name and after then instant name..
Like
C#
SERVER_NAME\SQLEXPRESS


or if it is local Server then

C#
.\SEQEXPRESS




in short servername\serverinstantname

Thank you.
   
v3
C#
public void store(string a)
        {
            SqlConnection connect=null;

            connect = new SqlConnection("server= localhost\sqlexpress ;  initial catalog=Student_Tracker DB ; integrated security= true ;");
            connect.Open();
            connect = new SqlConnection("insert into dbo.Student_Details (named) values (a)");
            connect.Close();
        }
   
C#
public void store(string a)
        {
            SqlConnection connect=null;

            connect = new SqlConnection("Data Source= (local) ;  initial catalog=Student_TrackerDB ; integrated security= true ;");
            connect.Open();
            connect = new SqlConnection("insert into dbo.Student_Details (named) values (a)");
            connect.Close();
        }


Remove the space between the "Student_Tracker DB" and Change the Database name and use Credentials if any. For example if you connect database using userID =sa then Also provide password.
   
v2
If your database name has spaces use brackets around it :
C#
connect = new SqlConnection("server= . ;  initial catalog=[Student_Tracker DB]; integrated security= true ;");

Or remove the space like : Student_Tracker_DB
   
public void store(string a)
{
SqlConnection connect=null;

connect = new SqlConnection("server= servername;initial catalog=Student_Tracker;User Id=userid; password=Password@123");
connect.Open();
SqlCommand cmd = new SqlCommand("Insert into Student_Details (named) values (a)", connect);
cmd.ExecuteReader();
connect.Close();
}

i got this solved :)
   
v2

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