1

I wanna connect to aspnetdb but it makes an error says "Login failed for user" this is the connection string in web config :

<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;Integrated Security=True;"
   providerName="System.Data.SqlClient" />

and this is my code:

SqlConnection connection = new SqlConnection();
        SqlCommand ComNewCheckSum = new SqlCommand();
        connection.ConnectionString = ConfigurationManager.ConnectionStrings["UserProfiles"].ConnectionString;
        connection.Open();
ComNewCheckSum.Connection = connection;
            ComNewCheckSum.CommandText = String.Format("select UserID from aspnet_Users where UserName = {0}", _UserName);

            return Convert.ToInt32(ComNewCheckSum.ExecuteScalar());

how can i pass through error? thank

1
  • two things - 1) have you tried logging into SQL Server (manually) with those credentials? does it work? 2) why are you manually executing SQL against the membership schema? Is there logic you require which is not covered by the Membership API? Membership.GetUser() not sufficient? Commented Oct 19, 2010 at 8:31

1 Answer 1

1

In your connection string you are using "Integrated Security=True", which means you are trying to connect to this database using your Windows credentials which it seems aren't good to access this database.

Try using a user and password that you know have access to this database and update your connections string so it uses that information - example:

<add name="UserProfiles" connectionString="Data Source=KIA;Initial Catalog=aspnetdb;User ID=someuser;Password=somepassword;"
   providerName="System.Data.SqlClient" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.