Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi am using windows form application in asp.net using c# langauge..am 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

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

       public Login()
       {
           InitializeComponent();
       }


 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())
            {
                conn.Close();
                Login.ActiveForm.Hide();
                Form f1 = new MDIParent1();
                f1.Show();
            }
            else
            {
                MessageBox.Show("The entered Username or Password is not correct");
}

can any one suggest me to solve this small problem..thank u
Posted
Updated 20-Jun-12 4:05am
v2

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 \.

FAHADSHEIKHJI/FAHADSHEIKHJI should be FAHADSHEIKHJI\FAHADSHEIKHJI
 
Share this answer
 
v2
Comments
ythisbug 20-Jun-12 10:58am    
thanks ryan if i use "\" am getting error "unrecognised escape sequence"..
ZurdoDev 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
ZurdoDev 20-Jun-12 11:17am    
Good to hear.
FAHADSHEIKHJI\FAHADSHEIKHJI
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..
 
Share this answer
 

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


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