none
Error Accessing Sql DataBase RRS feed

  • Question

  • Hi Everybody

    I'm new in ADO and I was trying to get data from my database from local server but I get Exception handling and Failed to Access the database

    Here is My Code:

     

     // Declare objects
    SqlConnection conn;
    SqlCommand comm;
    SqlDataReader reader;
    // Initialize connection
    conn = new SqlConnection("Server=localhost\\SqlExpress;" +
    "Database=MyDataBase;Integrated Security=True");
    
    // Create command
    comm = new SqlCommand(
      "SELECT EmployeeID, FirstName, Username, Password " +
    "FROM Employees", conn);
    
    try
    {
      // Open the connection
      conn.Open();
      // Execute the command
      reader = comm.ExecuteReader();
    
      // Bind the repeater to the data source
      myrepeater.DataSource = reader;
      myrepeater.DataBind();
      
    
      // Close the data reader
      reader.Close();
    }
    catch
    {
      // Display error message
      Response.Write("Error retrieving user data.");
    }
    finally
    {
      // Close the connection
      conn.Close();
    }
    Thanks in advance

     

     


    x00x
    Thursday, June 24, 2010 9:47 PM

Answers

  • Looks like your SQL Server does not allow Windows Authentication, or Windows Authentication is enabled but your account is not granted login permission. Try the forums under the SQL Server category if you need help enabling Windows Authentication or obtain access to SQL Server.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, June 25, 2010 10:10 PM

All replies

  • What is the exact error message?

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, June 25, 2010 12:31 AM
  • System.Data.SqlClient.SqlException was unhandled by user code

    Message:   Cannot open the DataBase "MyDataBase " Requested by the login. The login failed.

    Login failed for the user "MachineName\user"

    Source=".Net SqlClient Data Provider"

    ErrorCode=-2146232060

    Class=11

    LineNumber=65536

    Number=4060

    Procedure=""

    Server="localhost\\SqlExpress"

     

     


    x00x
    Friday, June 25, 2010 11:58 AM
  • Looks like your SQL Server does not allow Windows Authentication, or Windows Authentication is enabled but your account is not granted login permission. Try the forums under the SQL Server category if you need help enabling Windows Authentication or obtain access to SQL Server.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, June 25, 2010 10:10 PM