Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 ASP.NET4.0
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
 
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 20-Jun-12 5:04am
ythisbug2.1K
Edited 20-Jun-12 5:05am
v2
Rate this: bad
good
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 \.
 
FAHADSHEIKHJI/FAHADSHEIKHJI should be FAHADSHEIKHJI\FAHADSHEIKHJI
  Permalink  
v2
Comments
ythisbug at 20-Jun-12 10:58am
   
thanks ryan if i use "\" am getting error "unrecognised escape sequence"..
ryanb31 at 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 at 20-Jun-12 11:10am
   
thanks dude..modify ur asnwer i will accept..thanks again
ryanb31 at 20-Jun-12 11:17am
   
Good to hear.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 20 Apr 2013
Copyright © CodeProject, 1999-2014
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