Click here to Skip to main content
13,052,342 members (57,363 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi am using windows form application in using c# getting error while login to page

am getting 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)

here is my code

SqlConnection conn = new SqlConnection("Data Source=FAHADSHEIKHJI/FAHADSHEIKHJI;Initial Catalog=UAEExchangeShiroor;Integrated Security=True;");
       public Login()

 private void btnLogin_Click(object sender, EventArgs e)
            if (conn.State == ConnectionState.Open) { conn.Close(); }
            conn.Open();//this line am getting error
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("select * from tblLogin where logUserName='" + txtUserName.Text + "' and logPassword='" + txtPassword.Text + "'", conn);
            myReader = myCommand.ExecuteReader();
            if (myReader.Read())
                Form f1 = new MDIParent1();
                MessageBox.Show("The entered Username or Password is not correct");

can any one suggest me to solve this small problem..thank u
Posted 20-Jun-12 4:04am
Updated 20-Jun-12 4:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Change your connectionstring to use a backslash "\" instead of a "/". In C# use "\\" but if you move it to a web.config, just use single \.

ythisbug 20-Jun-12 10:58am
thanks ryan if i use "\" am getting error "unrecognised escape sequence"..
ryanb31 20-Jun-12 11:04am
Yes, in C# you need to actually do \\. The point is that the DataSource is the name of the server and then if you are not using the default instance of sql you need to do a \ and then the instance name. Try with \\
ythisbug 20-Jun-12 11:10am
thanks dude..modify ur asnwer i will accept..thanks again
ryanb31 20-Jun-12 11:17am
Good to hear.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

is the data source. Where u have saved d source file.. In which format it is being made.? I have the same problem.. APTTECH3 is my data source name. But i didnt find it anywhere in the folder. I need a help..

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100